cxd2841er.c 120 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * cxd2841er.c
  4. *
  5. * Sony digital demodulator driver for
  6. * CXD2841ER - DVB-S/S2/T/T2/C/C2
  7. * CXD2854ER - DVB-S/S2/T/T2/C/C2, ISDB-T/S
  8. *
  9. * Copyright 2012 Sony Corporation
  10. * Copyright (C) 2014 NetUP Inc.
  11. * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru>
  12. * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru>
  13. */
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/string.h>
  17. #include <linux/slab.h>
  18. #include <linux/bitops.h>
  19. #include <linux/math64.h>
  20. #include <linux/log2.h>
  21. #include <linux/dynamic_debug.h>
  22. #include <linux/kernel.h>
  23. #include <media/dvb_math.h>
  24. #include <media/dvb_frontend.h>
  25. #include "cxd2841er.h"
  26. #include "cxd2841er_priv.h"
  27. #define MAX_WRITE_REGSIZE 16
  28. #define LOG2_E_100X 144
  29. #define INTLOG10X100(x) ((u32) (((u64) intlog10(x) * 100) >> 24))
  30. /* DVB-C constellation */
  31. enum sony_dvbc_constellation_t {
  32. SONY_DVBC_CONSTELLATION_16QAM,
  33. SONY_DVBC_CONSTELLATION_32QAM,
  34. SONY_DVBC_CONSTELLATION_64QAM,
  35. SONY_DVBC_CONSTELLATION_128QAM,
  36. SONY_DVBC_CONSTELLATION_256QAM
  37. };
  38. enum cxd2841er_state {
  39. STATE_SHUTDOWN = 0,
  40. STATE_SLEEP_S,
  41. STATE_ACTIVE_S,
  42. STATE_SLEEP_TC,
  43. STATE_ACTIVE_TC
  44. };
  45. struct cxd2841er_priv {
  46. struct dvb_frontend frontend;
  47. struct i2c_adapter *i2c;
  48. u8 i2c_addr_slvx;
  49. u8 i2c_addr_slvt;
  50. const struct cxd2841er_config *config;
  51. enum cxd2841er_state state;
  52. u8 system;
  53. enum cxd2841er_xtal xtal;
  54. enum fe_caps caps;
  55. u32 flags;
  56. };
  57. static const struct cxd2841er_cnr_data s_cn_data[] = {
  58. { 0x033e, 0 }, { 0x0339, 100 }, { 0x0333, 200 },
  59. { 0x032e, 300 }, { 0x0329, 400 }, { 0x0324, 500 },
  60. { 0x031e, 600 }, { 0x0319, 700 }, { 0x0314, 800 },
  61. { 0x030f, 900 }, { 0x030a, 1000 }, { 0x02ff, 1100 },
  62. { 0x02f4, 1200 }, { 0x02e9, 1300 }, { 0x02de, 1400 },
  63. { 0x02d4, 1500 }, { 0x02c9, 1600 }, { 0x02bf, 1700 },
  64. { 0x02b5, 1800 }, { 0x02ab, 1900 }, { 0x02a1, 2000 },
  65. { 0x029b, 2100 }, { 0x0295, 2200 }, { 0x0290, 2300 },
  66. { 0x028a, 2400 }, { 0x0284, 2500 }, { 0x027f, 2600 },
  67. { 0x0279, 2700 }, { 0x0274, 2800 }, { 0x026e, 2900 },
  68. { 0x0269, 3000 }, { 0x0262, 3100 }, { 0x025c, 3200 },
  69. { 0x0255, 3300 }, { 0x024f, 3400 }, { 0x0249, 3500 },
  70. { 0x0242, 3600 }, { 0x023c, 3700 }, { 0x0236, 3800 },
  71. { 0x0230, 3900 }, { 0x022a, 4000 }, { 0x0223, 4100 },
  72. { 0x021c, 4200 }, { 0x0215, 4300 }, { 0x020e, 4400 },
  73. { 0x0207, 4500 }, { 0x0201, 4600 }, { 0x01fa, 4700 },
  74. { 0x01f4, 4800 }, { 0x01ed, 4900 }, { 0x01e7, 5000 },
  75. { 0x01e0, 5100 }, { 0x01d9, 5200 }, { 0x01d2, 5300 },
  76. { 0x01cb, 5400 }, { 0x01c4, 5500 }, { 0x01be, 5600 },
  77. { 0x01b7, 5700 }, { 0x01b1, 5800 }, { 0x01aa, 5900 },
  78. { 0x01a4, 6000 }, { 0x019d, 6100 }, { 0x0196, 6200 },
  79. { 0x018f, 6300 }, { 0x0189, 6400 }, { 0x0182, 6500 },
  80. { 0x017c, 6600 }, { 0x0175, 6700 }, { 0x016f, 6800 },
  81. { 0x0169, 6900 }, { 0x0163, 7000 }, { 0x015c, 7100 },
  82. { 0x0156, 7200 }, { 0x0150, 7300 }, { 0x014a, 7400 },
  83. { 0x0144, 7500 }, { 0x013e, 7600 }, { 0x0138, 7700 },
  84. { 0x0132, 7800 }, { 0x012d, 7900 }, { 0x0127, 8000 },
  85. { 0x0121, 8100 }, { 0x011c, 8200 }, { 0x0116, 8300 },
  86. { 0x0111, 8400 }, { 0x010b, 8500 }, { 0x0106, 8600 },
  87. { 0x0101, 8700 }, { 0x00fc, 8800 }, { 0x00f7, 8900 },
  88. { 0x00f2, 9000 }, { 0x00ee, 9100 }, { 0x00ea, 9200 },
  89. { 0x00e6, 9300 }, { 0x00e2, 9400 }, { 0x00de, 9500 },
  90. { 0x00da, 9600 }, { 0x00d7, 9700 }, { 0x00d3, 9800 },
  91. { 0x00d0, 9900 }, { 0x00cc, 10000 }, { 0x00c7, 10100 },
  92. { 0x00c3, 10200 }, { 0x00bf, 10300 }, { 0x00ba, 10400 },
  93. { 0x00b6, 10500 }, { 0x00b2, 10600 }, { 0x00ae, 10700 },
  94. { 0x00aa, 10800 }, { 0x00a7, 10900 }, { 0x00a3, 11000 },
  95. { 0x009f, 11100 }, { 0x009c, 11200 }, { 0x0098, 11300 },
  96. { 0x0094, 11400 }, { 0x0091, 11500 }, { 0x008e, 11600 },
  97. { 0x008a, 11700 }, { 0x0087, 11800 }, { 0x0084, 11900 },
  98. { 0x0081, 12000 }, { 0x007e, 12100 }, { 0x007b, 12200 },
  99. { 0x0079, 12300 }, { 0x0076, 12400 }, { 0x0073, 12500 },
  100. { 0x0071, 12600 }, { 0x006e, 12700 }, { 0x006c, 12800 },
  101. { 0x0069, 12900 }, { 0x0067, 13000 }, { 0x0065, 13100 },
  102. { 0x0062, 13200 }, { 0x0060, 13300 }, { 0x005e, 13400 },
  103. { 0x005c, 13500 }, { 0x005a, 13600 }, { 0x0058, 13700 },
  104. { 0x0056, 13800 }, { 0x0054, 13900 }, { 0x0052, 14000 },
  105. { 0x0050, 14100 }, { 0x004e, 14200 }, { 0x004c, 14300 },
  106. { 0x004b, 14400 }, { 0x0049, 14500 }, { 0x0047, 14600 },
  107. { 0x0046, 14700 }, { 0x0044, 14800 }, { 0x0043, 14900 },
  108. { 0x0041, 15000 }, { 0x003f, 15100 }, { 0x003e, 15200 },
  109. { 0x003c, 15300 }, { 0x003b, 15400 }, { 0x003a, 15500 },
  110. { 0x0037, 15700 }, { 0x0036, 15800 }, { 0x0034, 15900 },
  111. { 0x0033, 16000 }, { 0x0032, 16100 }, { 0x0031, 16200 },
  112. { 0x0030, 16300 }, { 0x002f, 16400 }, { 0x002e, 16500 },
  113. { 0x002d, 16600 }, { 0x002c, 16700 }, { 0x002b, 16800 },
  114. { 0x002a, 16900 }, { 0x0029, 17000 }, { 0x0028, 17100 },
  115. { 0x0027, 17200 }, { 0x0026, 17300 }, { 0x0025, 17400 },
  116. { 0x0024, 17500 }, { 0x0023, 17600 }, { 0x0022, 17800 },
  117. { 0x0021, 17900 }, { 0x0020, 18000 }, { 0x001f, 18200 },
  118. { 0x001e, 18300 }, { 0x001d, 18500 }, { 0x001c, 18700 },
  119. { 0x001b, 18900 }, { 0x001a, 19000 }, { 0x0019, 19200 },
  120. { 0x0018, 19300 }, { 0x0017, 19500 }, { 0x0016, 19700 },
  121. { 0x0015, 19900 }, { 0x0014, 20000 },
  122. };
  123. static const struct cxd2841er_cnr_data s2_cn_data[] = {
  124. { 0x05af, 0 }, { 0x0597, 100 }, { 0x057e, 200 },
  125. { 0x0567, 300 }, { 0x0550, 400 }, { 0x0539, 500 },
  126. { 0x0522, 600 }, { 0x050c, 700 }, { 0x04f6, 800 },
  127. { 0x04e1, 900 }, { 0x04cc, 1000 }, { 0x04b6, 1100 },
  128. { 0x04a1, 1200 }, { 0x048c, 1300 }, { 0x0477, 1400 },
  129. { 0x0463, 1500 }, { 0x044f, 1600 }, { 0x043c, 1700 },
  130. { 0x0428, 1800 }, { 0x0416, 1900 }, { 0x0403, 2000 },
  131. { 0x03ef, 2100 }, { 0x03dc, 2200 }, { 0x03c9, 2300 },
  132. { 0x03b6, 2400 }, { 0x03a4, 2500 }, { 0x0392, 2600 },
  133. { 0x0381, 2700 }, { 0x036f, 2800 }, { 0x035f, 2900 },
  134. { 0x034e, 3000 }, { 0x033d, 3100 }, { 0x032d, 3200 },
  135. { 0x031d, 3300 }, { 0x030d, 3400 }, { 0x02fd, 3500 },
  136. { 0x02ee, 3600 }, { 0x02df, 3700 }, { 0x02d0, 3800 },
  137. { 0x02c2, 3900 }, { 0x02b4, 4000 }, { 0x02a6, 4100 },
  138. { 0x0299, 4200 }, { 0x028c, 4300 }, { 0x027f, 4400 },
  139. { 0x0272, 4500 }, { 0x0265, 4600 }, { 0x0259, 4700 },
  140. { 0x024d, 4800 }, { 0x0241, 4900 }, { 0x0236, 5000 },
  141. { 0x022b, 5100 }, { 0x0220, 5200 }, { 0x0215, 5300 },
  142. { 0x020a, 5400 }, { 0x0200, 5500 }, { 0x01f6, 5600 },
  143. { 0x01ec, 5700 }, { 0x01e2, 5800 }, { 0x01d8, 5900 },
  144. { 0x01cf, 6000 }, { 0x01c6, 6100 }, { 0x01bc, 6200 },
  145. { 0x01b3, 6300 }, { 0x01aa, 6400 }, { 0x01a2, 6500 },
  146. { 0x0199, 6600 }, { 0x0191, 6700 }, { 0x0189, 6800 },
  147. { 0x0181, 6900 }, { 0x0179, 7000 }, { 0x0171, 7100 },
  148. { 0x0169, 7200 }, { 0x0161, 7300 }, { 0x015a, 7400 },
  149. { 0x0153, 7500 }, { 0x014b, 7600 }, { 0x0144, 7700 },
  150. { 0x013d, 7800 }, { 0x0137, 7900 }, { 0x0130, 8000 },
  151. { 0x012a, 8100 }, { 0x0124, 8200 }, { 0x011e, 8300 },
  152. { 0x0118, 8400 }, { 0x0112, 8500 }, { 0x010c, 8600 },
  153. { 0x0107, 8700 }, { 0x0101, 8800 }, { 0x00fc, 8900 },
  154. { 0x00f7, 9000 }, { 0x00f2, 9100 }, { 0x00ec, 9200 },
  155. { 0x00e7, 9300 }, { 0x00e2, 9400 }, { 0x00dd, 9500 },
  156. { 0x00d8, 9600 }, { 0x00d4, 9700 }, { 0x00cf, 9800 },
  157. { 0x00ca, 9900 }, { 0x00c6, 10000 }, { 0x00c2, 10100 },
  158. { 0x00be, 10200 }, { 0x00b9, 10300 }, { 0x00b5, 10400 },
  159. { 0x00b1, 10500 }, { 0x00ae, 10600 }, { 0x00aa, 10700 },
  160. { 0x00a6, 10800 }, { 0x00a3, 10900 }, { 0x009f, 11000 },
  161. { 0x009b, 11100 }, { 0x0098, 11200 }, { 0x0095, 11300 },
  162. { 0x0091, 11400 }, { 0x008e, 11500 }, { 0x008b, 11600 },
  163. { 0x0088, 11700 }, { 0x0085, 11800 }, { 0x0082, 11900 },
  164. { 0x007f, 12000 }, { 0x007c, 12100 }, { 0x007a, 12200 },
  165. { 0x0077, 12300 }, { 0x0074, 12400 }, { 0x0072, 12500 },
  166. { 0x006f, 12600 }, { 0x006d, 12700 }, { 0x006b, 12800 },
  167. { 0x0068, 12900 }, { 0x0066, 13000 }, { 0x0064, 13100 },
  168. { 0x0061, 13200 }, { 0x005f, 13300 }, { 0x005d, 13400 },
  169. { 0x005b, 13500 }, { 0x0059, 13600 }, { 0x0057, 13700 },
  170. { 0x0055, 13800 }, { 0x0053, 13900 }, { 0x0051, 14000 },
  171. { 0x004f, 14100 }, { 0x004e, 14200 }, { 0x004c, 14300 },
  172. { 0x004a, 14400 }, { 0x0049, 14500 }, { 0x0047, 14600 },
  173. { 0x0045, 14700 }, { 0x0044, 14800 }, { 0x0042, 14900 },
  174. { 0x0041, 15000 }, { 0x003f, 15100 }, { 0x003e, 15200 },
  175. { 0x003c, 15300 }, { 0x003b, 15400 }, { 0x003a, 15500 },
  176. { 0x0038, 15600 }, { 0x0037, 15700 }, { 0x0036, 15800 },
  177. { 0x0034, 15900 }, { 0x0033, 16000 }, { 0x0032, 16100 },
  178. { 0x0031, 16200 }, { 0x0030, 16300 }, { 0x002f, 16400 },
  179. { 0x002e, 16500 }, { 0x002d, 16600 }, { 0x002c, 16700 },
  180. { 0x002b, 16800 }, { 0x002a, 16900 }, { 0x0029, 17000 },
  181. { 0x0028, 17100 }, { 0x0027, 17200 }, { 0x0026, 17300 },
  182. { 0x0025, 17400 }, { 0x0024, 17500 }, { 0x0023, 17600 },
  183. { 0x0022, 17800 }, { 0x0021, 17900 }, { 0x0020, 18000 },
  184. { 0x001f, 18200 }, { 0x001e, 18300 }, { 0x001d, 18500 },
  185. { 0x001c, 18700 }, { 0x001b, 18900 }, { 0x001a, 19000 },
  186. { 0x0019, 19200 }, { 0x0018, 19300 }, { 0x0017, 19500 },
  187. { 0x0016, 19700 }, { 0x0015, 19900 }, { 0x0014, 20000 },
  188. };
  189. static int cxd2841er_freeze_regs(struct cxd2841er_priv *priv);
  190. static int cxd2841er_unfreeze_regs(struct cxd2841er_priv *priv);
  191. static void cxd2841er_i2c_debug(struct cxd2841er_priv *priv,
  192. u8 addr, u8 reg, u8 write,
  193. const u8 *data, u32 len)
  194. {
  195. dev_dbg(&priv->i2c->dev,
  196. "cxd2841er: I2C %s addr %02x reg 0x%02x size %d data %*ph\n",
  197. (write == 0 ? "read" : "write"), addr, reg, len, len, data);
  198. }
  199. static int cxd2841er_write_regs(struct cxd2841er_priv *priv,
  200. u8 addr, u8 reg, const u8 *data, u32 len)
  201. {
  202. int ret;
  203. u8 buf[MAX_WRITE_REGSIZE + 1];
  204. u8 i2c_addr = (addr == I2C_SLVX ?
  205. priv->i2c_addr_slvx : priv->i2c_addr_slvt);
  206. struct i2c_msg msg[1] = {
  207. {
  208. .addr = i2c_addr,
  209. .flags = 0,
  210. .len = len + 1,
  211. .buf = buf,
  212. }
  213. };
  214. if (len + 1 >= sizeof(buf)) {
  215. dev_warn(&priv->i2c->dev, "wr reg=%04x: len=%d is too big!\n",
  216. reg, len + 1);
  217. return -E2BIG;
  218. }
  219. cxd2841er_i2c_debug(priv, i2c_addr, reg, 1, data, len);
  220. buf[0] = reg;
  221. memcpy(&buf[1], data, len);
  222. ret = i2c_transfer(priv->i2c, msg, 1);
  223. if (ret >= 0 && ret != 1)
  224. ret = -EIO;
  225. if (ret < 0) {
  226. dev_warn(&priv->i2c->dev,
  227. "%s: i2c wr failed=%d addr=%02x reg=%02x len=%d\n",
  228. KBUILD_MODNAME, ret, i2c_addr, reg, len);
  229. return ret;
  230. }
  231. return 0;
  232. }
  233. static int cxd2841er_write_reg(struct cxd2841er_priv *priv,
  234. u8 addr, u8 reg, u8 val)
  235. {
  236. u8 tmp = val; /* see gcc.gnu.org/bugzilla/show_bug.cgi?id=81715 */
  237. return cxd2841er_write_regs(priv, addr, reg, &tmp, 1);
  238. }
  239. static int cxd2841er_read_regs(struct cxd2841er_priv *priv,
  240. u8 addr, u8 reg, u8 *val, u32 len)
  241. {
  242. int ret;
  243. u8 i2c_addr = (addr == I2C_SLVX ?
  244. priv->i2c_addr_slvx : priv->i2c_addr_slvt);
  245. struct i2c_msg msg[2] = {
  246. {
  247. .addr = i2c_addr,
  248. .flags = 0,
  249. .len = 1,
  250. .buf = &reg,
  251. }, {
  252. .addr = i2c_addr,
  253. .flags = I2C_M_RD,
  254. .len = len,
  255. .buf = val,
  256. }
  257. };
  258. ret = i2c_transfer(priv->i2c, msg, 2);
  259. if (ret >= 0 && ret != 2)
  260. ret = -EIO;
  261. if (ret < 0) {
  262. dev_warn(&priv->i2c->dev,
  263. "%s: i2c rd failed=%d addr=%02x reg=%02x\n",
  264. KBUILD_MODNAME, ret, i2c_addr, reg);
  265. return ret;
  266. }
  267. cxd2841er_i2c_debug(priv, i2c_addr, reg, 0, val, len);
  268. return 0;
  269. }
  270. static int cxd2841er_read_reg(struct cxd2841er_priv *priv,
  271. u8 addr, u8 reg, u8 *val)
  272. {
  273. return cxd2841er_read_regs(priv, addr, reg, val, 1);
  274. }
  275. static int cxd2841er_set_reg_bits(struct cxd2841er_priv *priv,
  276. u8 addr, u8 reg, u8 data, u8 mask)
  277. {
  278. int res;
  279. u8 rdata;
  280. if (mask != 0xff) {
  281. res = cxd2841er_read_reg(priv, addr, reg, &rdata);
  282. if (res)
  283. return res;
  284. data = ((data & mask) | (rdata & (mask ^ 0xFF)));
  285. }
  286. return cxd2841er_write_reg(priv, addr, reg, data);
  287. }
  288. static u32 cxd2841er_calc_iffreq_xtal(enum cxd2841er_xtal xtal, u32 ifhz)
  289. {
  290. u64 tmp;
  291. tmp = (u64) ifhz * 16777216;
  292. do_div(tmp, ((xtal == SONY_XTAL_24000) ? 48000000 : 41000000));
  293. return (u32) tmp;
  294. }
  295. static u32 cxd2841er_calc_iffreq(u32 ifhz)
  296. {
  297. return cxd2841er_calc_iffreq_xtal(SONY_XTAL_20500, ifhz);
  298. }
  299. static int cxd2841er_get_if_hz(struct cxd2841er_priv *priv, u32 def_hz)
  300. {
  301. u32 hz;
  302. if (priv->frontend.ops.tuner_ops.get_if_frequency
  303. && (priv->flags & CXD2841ER_AUTO_IFHZ))
  304. priv->frontend.ops.tuner_ops.get_if_frequency(
  305. &priv->frontend, &hz);
  306. else
  307. hz = def_hz;
  308. return hz;
  309. }
  310. static int cxd2841er_tuner_set(struct dvb_frontend *fe)
  311. {
  312. struct cxd2841er_priv *priv = fe->demodulator_priv;
  313. if ((priv->flags & CXD2841ER_USE_GATECTRL) && fe->ops.i2c_gate_ctrl)
  314. fe->ops.i2c_gate_ctrl(fe, 1);
  315. if (fe->ops.tuner_ops.set_params)
  316. fe->ops.tuner_ops.set_params(fe);
  317. if ((priv->flags & CXD2841ER_USE_GATECTRL) && fe->ops.i2c_gate_ctrl)
  318. fe->ops.i2c_gate_ctrl(fe, 0);
  319. return 0;
  320. }
  321. static int cxd2841er_dvbs2_set_symbol_rate(struct cxd2841er_priv *priv,
  322. u32 symbol_rate)
  323. {
  324. u32 reg_value = 0;
  325. u8 data[3] = {0, 0, 0};
  326. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  327. /*
  328. * regValue = (symbolRateKSps * 2^14 / 1000) + 0.5
  329. * = ((symbolRateKSps * 2^14) + 500) / 1000
  330. * = ((symbolRateKSps * 16384) + 500) / 1000
  331. */
  332. reg_value = DIV_ROUND_CLOSEST(symbol_rate * 16384, 1000);
  333. if ((reg_value == 0) || (reg_value > 0xFFFFF)) {
  334. dev_err(&priv->i2c->dev,
  335. "%s(): reg_value is out of range\n", __func__);
  336. return -EINVAL;
  337. }
  338. data[0] = (u8)((reg_value >> 16) & 0x0F);
  339. data[1] = (u8)((reg_value >> 8) & 0xFF);
  340. data[2] = (u8)(reg_value & 0xFF);
  341. /* Set SLV-T Bank : 0xAE */
  342. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xae);
  343. cxd2841er_write_regs(priv, I2C_SLVT, 0x20, data, 3);
  344. return 0;
  345. }
  346. static void cxd2841er_set_ts_clock_mode(struct cxd2841er_priv *priv,
  347. u8 system);
  348. static int cxd2841er_sleep_s_to_active_s(struct cxd2841er_priv *priv,
  349. u8 system, u32 symbol_rate)
  350. {
  351. int ret;
  352. u8 data[4] = { 0, 0, 0, 0 };
  353. if (priv->state != STATE_SLEEP_S) {
  354. dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
  355. __func__, (int)priv->state);
  356. return -EINVAL;
  357. }
  358. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  359. cxd2841er_set_ts_clock_mode(priv, SYS_DVBS);
  360. /* Set demod mode */
  361. if (system == SYS_DVBS) {
  362. data[0] = 0x0A;
  363. } else if (system == SYS_DVBS2) {
  364. data[0] = 0x0B;
  365. } else {
  366. dev_err(&priv->i2c->dev, "%s(): invalid delsys %d\n",
  367. __func__, system);
  368. return -EINVAL;
  369. }
  370. /* Set SLV-X Bank : 0x00 */
  371. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  372. cxd2841er_write_reg(priv, I2C_SLVX, 0x17, data[0]);
  373. /* DVB-S/S2 */
  374. data[0] = 0x00;
  375. /* Set SLV-T Bank : 0x00 */
  376. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  377. /* Enable S/S2 auto detection 1 */
  378. cxd2841er_write_reg(priv, I2C_SLVT, 0x2d, data[0]);
  379. /* Set SLV-T Bank : 0xAE */
  380. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xae);
  381. /* Enable S/S2 auto detection 2 */
  382. cxd2841er_write_reg(priv, I2C_SLVT, 0x30, data[0]);
  383. /* Set SLV-T Bank : 0x00 */
  384. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  385. /* Enable demod clock */
  386. cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01);
  387. /* Enable ADC clock */
  388. cxd2841er_write_reg(priv, I2C_SLVT, 0x31, 0x01);
  389. /* Enable ADC 1 */
  390. cxd2841er_write_reg(priv, I2C_SLVT, 0x63, 0x16);
  391. /* Enable ADC 2 */
  392. cxd2841er_write_reg(priv, I2C_SLVT, 0x65, 0x3f);
  393. /* Set SLV-X Bank : 0x00 */
  394. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  395. /* Enable ADC 3 */
  396. cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00);
  397. /* Set SLV-T Bank : 0xA3 */
  398. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa3);
  399. cxd2841er_write_reg(priv, I2C_SLVT, 0xac, 0x00);
  400. data[0] = 0x07;
  401. data[1] = 0x3B;
  402. data[2] = 0x08;
  403. data[3] = 0xC5;
  404. /* Set SLV-T Bank : 0xAB */
  405. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xab);
  406. cxd2841er_write_regs(priv, I2C_SLVT, 0x98, data, 4);
  407. data[0] = 0x05;
  408. data[1] = 0x80;
  409. data[2] = 0x0A;
  410. data[3] = 0x80;
  411. cxd2841er_write_regs(priv, I2C_SLVT, 0xa8, data, 4);
  412. data[0] = 0x0C;
  413. data[1] = 0xCC;
  414. cxd2841er_write_regs(priv, I2C_SLVT, 0xc3, data, 2);
  415. /* Set demod parameter */
  416. ret = cxd2841er_dvbs2_set_symbol_rate(priv, symbol_rate);
  417. if (ret != 0)
  418. return ret;
  419. /* Set SLV-T Bank : 0x00 */
  420. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  421. /* disable Hi-Z setting 1 */
  422. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x10);
  423. /* disable Hi-Z setting 2 */
  424. cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00);
  425. priv->state = STATE_ACTIVE_S;
  426. return 0;
  427. }
  428. static int cxd2841er_sleep_tc_to_active_t_band(struct cxd2841er_priv *priv,
  429. u32 bandwidth);
  430. static int cxd2841er_sleep_tc_to_active_t2_band(struct cxd2841er_priv *priv,
  431. u32 bandwidth);
  432. static int cxd2841er_sleep_tc_to_active_c_band(struct cxd2841er_priv *priv,
  433. u32 bandwidth);
  434. static int cxd2841er_sleep_tc_to_active_i(struct cxd2841er_priv *priv,
  435. u32 bandwidth);
  436. static int cxd2841er_active_i_to_sleep_tc(struct cxd2841er_priv *priv);
  437. static int cxd2841er_sleep_tc_to_shutdown(struct cxd2841er_priv *priv);
  438. static int cxd2841er_shutdown_to_sleep_tc(struct cxd2841er_priv *priv);
  439. static int cxd2841er_sleep_tc(struct dvb_frontend *fe);
  440. static int cxd2841er_retune_active(struct cxd2841er_priv *priv,
  441. struct dtv_frontend_properties *p)
  442. {
  443. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  444. if (priv->state != STATE_ACTIVE_S &&
  445. priv->state != STATE_ACTIVE_TC) {
  446. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  447. __func__, priv->state);
  448. return -EINVAL;
  449. }
  450. /* Set SLV-T Bank : 0x00 */
  451. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  452. /* disable TS output */
  453. cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01);
  454. if (priv->state == STATE_ACTIVE_S)
  455. return cxd2841er_dvbs2_set_symbol_rate(
  456. priv, p->symbol_rate / 1000);
  457. else if (priv->state == STATE_ACTIVE_TC) {
  458. switch (priv->system) {
  459. case SYS_DVBT:
  460. return cxd2841er_sleep_tc_to_active_t_band(
  461. priv, p->bandwidth_hz);
  462. case SYS_DVBT2:
  463. return cxd2841er_sleep_tc_to_active_t2_band(
  464. priv, p->bandwidth_hz);
  465. case SYS_DVBC_ANNEX_A:
  466. return cxd2841er_sleep_tc_to_active_c_band(
  467. priv, p->bandwidth_hz);
  468. case SYS_ISDBT:
  469. cxd2841er_active_i_to_sleep_tc(priv);
  470. cxd2841er_sleep_tc_to_shutdown(priv);
  471. cxd2841er_shutdown_to_sleep_tc(priv);
  472. return cxd2841er_sleep_tc_to_active_i(
  473. priv, p->bandwidth_hz);
  474. }
  475. }
  476. dev_dbg(&priv->i2c->dev, "%s(): invalid delivery system %d\n",
  477. __func__, priv->system);
  478. return -EINVAL;
  479. }
  480. static int cxd2841er_active_s_to_sleep_s(struct cxd2841er_priv *priv)
  481. {
  482. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  483. if (priv->state != STATE_ACTIVE_S) {
  484. dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
  485. __func__, priv->state);
  486. return -EINVAL;
  487. }
  488. /* Set SLV-T Bank : 0x00 */
  489. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  490. /* disable TS output */
  491. cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01);
  492. /* enable Hi-Z setting 1 */
  493. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x1f);
  494. /* enable Hi-Z setting 2 */
  495. cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff);
  496. /* Set SLV-X Bank : 0x00 */
  497. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  498. /* disable ADC 1 */
  499. cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01);
  500. /* Set SLV-T Bank : 0x00 */
  501. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  502. /* disable ADC clock */
  503. cxd2841er_write_reg(priv, I2C_SLVT, 0x31, 0x00);
  504. /* disable ADC 2 */
  505. cxd2841er_write_reg(priv, I2C_SLVT, 0x63, 0x16);
  506. /* disable ADC 3 */
  507. cxd2841er_write_reg(priv, I2C_SLVT, 0x65, 0x27);
  508. /* SADC Bias ON */
  509. cxd2841er_write_reg(priv, I2C_SLVT, 0x69, 0x06);
  510. /* disable demod clock */
  511. cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00);
  512. /* Set SLV-T Bank : 0xAE */
  513. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xae);
  514. /* disable S/S2 auto detection1 */
  515. cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
  516. /* Set SLV-T Bank : 0x00 */
  517. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  518. /* disable S/S2 auto detection2 */
  519. cxd2841er_write_reg(priv, I2C_SLVT, 0x2d, 0x00);
  520. priv->state = STATE_SLEEP_S;
  521. return 0;
  522. }
  523. static int cxd2841er_sleep_s_to_shutdown(struct cxd2841er_priv *priv)
  524. {
  525. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  526. if (priv->state != STATE_SLEEP_S) {
  527. dev_dbg(&priv->i2c->dev, "%s(): invalid demod state %d\n",
  528. __func__, priv->state);
  529. return -EINVAL;
  530. }
  531. /* Set SLV-T Bank : 0x00 */
  532. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  533. /* Disable DSQOUT */
  534. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f);
  535. /* Disable DSQIN */
  536. cxd2841er_write_reg(priv, I2C_SLVT, 0x9c, 0x00);
  537. /* Set SLV-X Bank : 0x00 */
  538. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  539. /* Disable oscillator */
  540. cxd2841er_write_reg(priv, I2C_SLVX, 0x15, 0x01);
  541. /* Set demod mode */
  542. cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x01);
  543. priv->state = STATE_SHUTDOWN;
  544. return 0;
  545. }
  546. static int cxd2841er_sleep_tc_to_shutdown(struct cxd2841er_priv *priv)
  547. {
  548. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  549. if (priv->state != STATE_SLEEP_TC) {
  550. dev_dbg(&priv->i2c->dev, "%s(): invalid demod state %d\n",
  551. __func__, priv->state);
  552. return -EINVAL;
  553. }
  554. /* Set SLV-X Bank : 0x00 */
  555. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  556. /* Disable oscillator */
  557. cxd2841er_write_reg(priv, I2C_SLVX, 0x15, 0x01);
  558. /* Set demod mode */
  559. cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x01);
  560. priv->state = STATE_SHUTDOWN;
  561. return 0;
  562. }
  563. static int cxd2841er_active_t_to_sleep_tc(struct cxd2841er_priv *priv)
  564. {
  565. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  566. if (priv->state != STATE_ACTIVE_TC) {
  567. dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
  568. __func__, priv->state);
  569. return -EINVAL;
  570. }
  571. /* Set SLV-T Bank : 0x00 */
  572. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  573. /* disable TS output */
  574. cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01);
  575. /* enable Hi-Z setting 1 */
  576. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f);
  577. /* enable Hi-Z setting 2 */
  578. cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff);
  579. /* Set SLV-X Bank : 0x00 */
  580. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  581. /* disable ADC 1 */
  582. cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01);
  583. /* Set SLV-T Bank : 0x00 */
  584. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  585. /* Disable ADC 2 */
  586. cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a);
  587. /* Disable ADC 3 */
  588. cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a);
  589. /* Disable ADC clock */
  590. cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
  591. /* Disable RF level monitor */
  592. cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00);
  593. /* Disable demod clock */
  594. cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00);
  595. priv->state = STATE_SLEEP_TC;
  596. return 0;
  597. }
  598. static int cxd2841er_active_t2_to_sleep_tc(struct cxd2841er_priv *priv)
  599. {
  600. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  601. if (priv->state != STATE_ACTIVE_TC) {
  602. dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
  603. __func__, priv->state);
  604. return -EINVAL;
  605. }
  606. /* Set SLV-T Bank : 0x00 */
  607. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  608. /* disable TS output */
  609. cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01);
  610. /* enable Hi-Z setting 1 */
  611. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f);
  612. /* enable Hi-Z setting 2 */
  613. cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff);
  614. /* Cancel DVB-T2 setting */
  615. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x13);
  616. cxd2841er_write_reg(priv, I2C_SLVT, 0x83, 0x40);
  617. cxd2841er_write_reg(priv, I2C_SLVT, 0x86, 0x21);
  618. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x9e, 0x09, 0x0f);
  619. cxd2841er_write_reg(priv, I2C_SLVT, 0x9f, 0xfb);
  620. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2a);
  621. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x38, 0x00, 0x0f);
  622. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2b);
  623. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x11, 0x00, 0x3f);
  624. /* Set SLV-X Bank : 0x00 */
  625. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  626. /* disable ADC 1 */
  627. cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01);
  628. /* Set SLV-T Bank : 0x00 */
  629. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  630. /* Disable ADC 2 */
  631. cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a);
  632. /* Disable ADC 3 */
  633. cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a);
  634. /* Disable ADC clock */
  635. cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
  636. /* Disable RF level monitor */
  637. cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00);
  638. /* Disable demod clock */
  639. cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00);
  640. priv->state = STATE_SLEEP_TC;
  641. return 0;
  642. }
  643. static int cxd2841er_active_c_to_sleep_tc(struct cxd2841er_priv *priv)
  644. {
  645. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  646. if (priv->state != STATE_ACTIVE_TC) {
  647. dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
  648. __func__, priv->state);
  649. return -EINVAL;
  650. }
  651. /* Set SLV-T Bank : 0x00 */
  652. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  653. /* disable TS output */
  654. cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01);
  655. /* enable Hi-Z setting 1 */
  656. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f);
  657. /* enable Hi-Z setting 2 */
  658. cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff);
  659. /* Cancel DVB-C setting */
  660. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11);
  661. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa3, 0x00, 0x1f);
  662. /* Set SLV-X Bank : 0x00 */
  663. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  664. /* disable ADC 1 */
  665. cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01);
  666. /* Set SLV-T Bank : 0x00 */
  667. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  668. /* Disable ADC 2 */
  669. cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a);
  670. /* Disable ADC 3 */
  671. cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a);
  672. /* Disable ADC clock */
  673. cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
  674. /* Disable RF level monitor */
  675. cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00);
  676. /* Disable demod clock */
  677. cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00);
  678. priv->state = STATE_SLEEP_TC;
  679. return 0;
  680. }
  681. static int cxd2841er_active_i_to_sleep_tc(struct cxd2841er_priv *priv)
  682. {
  683. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  684. if (priv->state != STATE_ACTIVE_TC) {
  685. dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
  686. __func__, priv->state);
  687. return -EINVAL;
  688. }
  689. /* Set SLV-T Bank : 0x00 */
  690. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  691. /* disable TS output */
  692. cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01);
  693. /* enable Hi-Z setting 1 */
  694. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f);
  695. /* enable Hi-Z setting 2 */
  696. cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff);
  697. /* TODO: Cancel demod parameter */
  698. /* Set SLV-X Bank : 0x00 */
  699. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  700. /* disable ADC 1 */
  701. cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01);
  702. /* Set SLV-T Bank : 0x00 */
  703. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  704. /* Disable ADC 2 */
  705. cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a);
  706. /* Disable ADC 3 */
  707. cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a);
  708. /* Disable ADC clock */
  709. cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
  710. /* Disable RF level monitor */
  711. cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00);
  712. /* Disable demod clock */
  713. cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00);
  714. priv->state = STATE_SLEEP_TC;
  715. return 0;
  716. }
  717. static int cxd2841er_shutdown_to_sleep_s(struct cxd2841er_priv *priv)
  718. {
  719. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  720. if (priv->state != STATE_SHUTDOWN) {
  721. dev_dbg(&priv->i2c->dev, "%s(): invalid demod state %d\n",
  722. __func__, priv->state);
  723. return -EINVAL;
  724. }
  725. /* Set SLV-X Bank : 0x00 */
  726. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  727. /* Clear all demodulator registers */
  728. cxd2841er_write_reg(priv, I2C_SLVX, 0x02, 0x00);
  729. usleep_range(3000, 5000);
  730. /* Set SLV-X Bank : 0x00 */
  731. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  732. /* Set demod SW reset */
  733. cxd2841er_write_reg(priv, I2C_SLVX, 0x10, 0x01);
  734. switch (priv->xtal) {
  735. case SONY_XTAL_20500:
  736. cxd2841er_write_reg(priv, I2C_SLVX, 0x14, 0x00);
  737. break;
  738. case SONY_XTAL_24000:
  739. /* Select demod frequency */
  740. cxd2841er_write_reg(priv, I2C_SLVX, 0x12, 0x00);
  741. cxd2841er_write_reg(priv, I2C_SLVX, 0x14, 0x03);
  742. break;
  743. case SONY_XTAL_41000:
  744. cxd2841er_write_reg(priv, I2C_SLVX, 0x14, 0x01);
  745. break;
  746. default:
  747. dev_dbg(&priv->i2c->dev, "%s(): invalid demod xtal %d\n",
  748. __func__, priv->xtal);
  749. return -EINVAL;
  750. }
  751. /* Set demod mode */
  752. cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x0a);
  753. /* Clear demod SW reset */
  754. cxd2841er_write_reg(priv, I2C_SLVX, 0x10, 0x00);
  755. usleep_range(1000, 2000);
  756. /* Set SLV-T Bank : 0x00 */
  757. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  758. /* enable DSQOUT */
  759. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x1F);
  760. /* enable DSQIN */
  761. cxd2841er_write_reg(priv, I2C_SLVT, 0x9C, 0x40);
  762. /* TADC Bias On */
  763. cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a);
  764. cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a);
  765. /* SADC Bias On */
  766. cxd2841er_write_reg(priv, I2C_SLVT, 0x63, 0x16);
  767. cxd2841er_write_reg(priv, I2C_SLVT, 0x65, 0x27);
  768. cxd2841er_write_reg(priv, I2C_SLVT, 0x69, 0x06);
  769. priv->state = STATE_SLEEP_S;
  770. return 0;
  771. }
  772. static int cxd2841er_shutdown_to_sleep_tc(struct cxd2841er_priv *priv)
  773. {
  774. u8 data = 0;
  775. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  776. if (priv->state != STATE_SHUTDOWN) {
  777. dev_dbg(&priv->i2c->dev, "%s(): invalid demod state %d\n",
  778. __func__, priv->state);
  779. return -EINVAL;
  780. }
  781. /* Set SLV-X Bank : 0x00 */
  782. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  783. /* Clear all demodulator registers */
  784. cxd2841er_write_reg(priv, I2C_SLVX, 0x02, 0x00);
  785. usleep_range(3000, 5000);
  786. /* Set SLV-X Bank : 0x00 */
  787. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  788. /* Set demod SW reset */
  789. cxd2841er_write_reg(priv, I2C_SLVX, 0x10, 0x01);
  790. /* Select ADC clock mode */
  791. cxd2841er_write_reg(priv, I2C_SLVX, 0x13, 0x00);
  792. switch (priv->xtal) {
  793. case SONY_XTAL_20500:
  794. data = 0x0;
  795. break;
  796. case SONY_XTAL_24000:
  797. /* Select demod frequency */
  798. cxd2841er_write_reg(priv, I2C_SLVX, 0x12, 0x00);
  799. data = 0x3;
  800. break;
  801. case SONY_XTAL_41000:
  802. cxd2841er_write_reg(priv, I2C_SLVX, 0x12, 0x00);
  803. data = 0x1;
  804. break;
  805. }
  806. cxd2841er_write_reg(priv, I2C_SLVX, 0x14, data);
  807. /* Clear demod SW reset */
  808. cxd2841er_write_reg(priv, I2C_SLVX, 0x10, 0x00);
  809. usleep_range(1000, 2000);
  810. /* Set SLV-T Bank : 0x00 */
  811. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  812. /* TADC Bias On */
  813. cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a);
  814. cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a);
  815. /* SADC Bias On */
  816. cxd2841er_write_reg(priv, I2C_SLVT, 0x63, 0x16);
  817. cxd2841er_write_reg(priv, I2C_SLVT, 0x65, 0x27);
  818. cxd2841er_write_reg(priv, I2C_SLVT, 0x69, 0x06);
  819. priv->state = STATE_SLEEP_TC;
  820. return 0;
  821. }
  822. static int cxd2841er_tune_done(struct cxd2841er_priv *priv)
  823. {
  824. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  825. /* Set SLV-T Bank : 0x00 */
  826. cxd2841er_write_reg(priv, I2C_SLVT, 0, 0);
  827. /* SW Reset */
  828. cxd2841er_write_reg(priv, I2C_SLVT, 0xfe, 0x01);
  829. /* Enable TS output */
  830. cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x00);
  831. return 0;
  832. }
  833. /* Set TS parallel mode */
  834. static void cxd2841er_set_ts_clock_mode(struct cxd2841er_priv *priv,
  835. u8 system)
  836. {
  837. u8 serial_ts, ts_rate_ctrl_off, ts_in_off;
  838. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  839. /* Set SLV-T Bank : 0x00 */
  840. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  841. cxd2841er_read_reg(priv, I2C_SLVT, 0xc4, &serial_ts);
  842. cxd2841er_read_reg(priv, I2C_SLVT, 0xd3, &ts_rate_ctrl_off);
  843. cxd2841er_read_reg(priv, I2C_SLVT, 0xde, &ts_in_off);
  844. dev_dbg(&priv->i2c->dev, "%s(): ser_ts=0x%02x rate_ctrl_off=0x%02x in_off=0x%02x\n",
  845. __func__, serial_ts, ts_rate_ctrl_off, ts_in_off);
  846. /*
  847. * slave Bank Addr Bit default Name
  848. * <SLV-T> 00h C4h [1:0] 2'b?? OSERCKMODE
  849. */
  850. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xc4,
  851. ((priv->flags & CXD2841ER_TS_SERIAL) ? 0x01 : 0x00), 0x03);
  852. /*
  853. * slave Bank Addr Bit default Name
  854. * <SLV-T> 00h D1h [1:0] 2'b?? OSERDUTYMODE
  855. */
  856. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd1,
  857. ((priv->flags & CXD2841ER_TS_SERIAL) ? 0x01 : 0x00), 0x03);
  858. /*
  859. * slave Bank Addr Bit default Name
  860. * <SLV-T> 00h D9h [7:0] 8'h08 OTSCKPERIOD
  861. */
  862. cxd2841er_write_reg(priv, I2C_SLVT, 0xd9, 0x08);
  863. /*
  864. * Disable TS IF Clock
  865. * slave Bank Addr Bit default Name
  866. * <SLV-T> 00h 32h [0] 1'b1 OREG_CK_TSIF_EN
  867. */
  868. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x32, 0x00, 0x01);
  869. /*
  870. * slave Bank Addr Bit default Name
  871. * <SLV-T> 00h 33h [1:0] 2'b01 OREG_CKSEL_TSIF
  872. */
  873. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x33,
  874. ((priv->flags & CXD2841ER_TS_SERIAL) ? 0x01 : 0x00), 0x03);
  875. /*
  876. * Enable TS IF Clock
  877. * slave Bank Addr Bit default Name
  878. * <SLV-T> 00h 32h [0] 1'b1 OREG_CK_TSIF_EN
  879. */
  880. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x32, 0x01, 0x01);
  881. if (system == SYS_DVBT) {
  882. /* Enable parity period for DVB-T */
  883. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  884. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x66, 0x01, 0x01);
  885. } else if (system == SYS_DVBC_ANNEX_A) {
  886. /* Enable parity period for DVB-C */
  887. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40);
  888. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x66, 0x01, 0x01);
  889. }
  890. }
  891. static u8 cxd2841er_chip_id(struct cxd2841er_priv *priv)
  892. {
  893. u8 chip_id = 0;
  894. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  895. if (cxd2841er_write_reg(priv, I2C_SLVT, 0, 0) == 0)
  896. cxd2841er_read_reg(priv, I2C_SLVT, 0xfd, &chip_id);
  897. else if (cxd2841er_write_reg(priv, I2C_SLVX, 0, 0) == 0)
  898. cxd2841er_read_reg(priv, I2C_SLVX, 0xfd, &chip_id);
  899. return chip_id;
  900. }
  901. static int cxd2841er_read_status_s(struct dvb_frontend *fe,
  902. enum fe_status *status)
  903. {
  904. u8 reg = 0;
  905. struct cxd2841er_priv *priv = fe->demodulator_priv;
  906. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  907. *status = 0;
  908. if (priv->state != STATE_ACTIVE_S) {
  909. dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
  910. __func__, priv->state);
  911. return -EINVAL;
  912. }
  913. /* Set SLV-T Bank : 0xA0 */
  914. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0);
  915. /*
  916. * slave Bank Addr Bit Signal name
  917. * <SLV-T> A0h 11h [2] ITSLOCK
  918. */
  919. cxd2841er_read_reg(priv, I2C_SLVT, 0x11, &reg);
  920. if (reg & 0x04) {
  921. *status = FE_HAS_SIGNAL
  922. | FE_HAS_CARRIER
  923. | FE_HAS_VITERBI
  924. | FE_HAS_SYNC
  925. | FE_HAS_LOCK;
  926. }
  927. dev_dbg(&priv->i2c->dev, "%s(): result 0x%x\n", __func__, *status);
  928. return 0;
  929. }
  930. static int cxd2841er_read_status_t_t2(struct cxd2841er_priv *priv,
  931. u8 *sync, u8 *tslock, u8 *unlock)
  932. {
  933. u8 data = 0;
  934. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  935. if (priv->state != STATE_ACTIVE_TC)
  936. return -EINVAL;
  937. if (priv->system == SYS_DVBT) {
  938. /* Set SLV-T Bank : 0x10 */
  939. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  940. } else {
  941. /* Set SLV-T Bank : 0x20 */
  942. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20);
  943. }
  944. cxd2841er_read_reg(priv, I2C_SLVT, 0x10, &data);
  945. if ((data & 0x07) == 0x07) {
  946. dev_dbg(&priv->i2c->dev,
  947. "%s(): invalid hardware state detected\n", __func__);
  948. *sync = 0;
  949. *tslock = 0;
  950. *unlock = 0;
  951. } else {
  952. *sync = ((data & 0x07) == 0x6 ? 1 : 0);
  953. *tslock = ((data & 0x20) ? 1 : 0);
  954. *unlock = ((data & 0x10) ? 1 : 0);
  955. }
  956. return 0;
  957. }
  958. static int cxd2841er_read_status_c(struct cxd2841er_priv *priv, u8 *tslock)
  959. {
  960. u8 data;
  961. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  962. if (priv->state != STATE_ACTIVE_TC)
  963. return -EINVAL;
  964. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40);
  965. cxd2841er_read_reg(priv, I2C_SLVT, 0x88, &data);
  966. if ((data & 0x01) == 0) {
  967. *tslock = 0;
  968. } else {
  969. cxd2841er_read_reg(priv, I2C_SLVT, 0x10, &data);
  970. *tslock = ((data & 0x20) ? 1 : 0);
  971. }
  972. return 0;
  973. }
  974. static int cxd2841er_read_status_i(struct cxd2841er_priv *priv,
  975. u8 *sync, u8 *tslock, u8 *unlock)
  976. {
  977. u8 data = 0;
  978. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  979. if (priv->state != STATE_ACTIVE_TC)
  980. return -EINVAL;
  981. /* Set SLV-T Bank : 0x60 */
  982. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x60);
  983. cxd2841er_read_reg(priv, I2C_SLVT, 0x10, &data);
  984. dev_dbg(&priv->i2c->dev,
  985. "%s(): lock=0x%x\n", __func__, data);
  986. *sync = ((data & 0x02) ? 1 : 0);
  987. *tslock = ((data & 0x01) ? 1 : 0);
  988. *unlock = ((data & 0x10) ? 1 : 0);
  989. return 0;
  990. }
  991. static int cxd2841er_read_status_tc(struct dvb_frontend *fe,
  992. enum fe_status *status)
  993. {
  994. int ret = 0;
  995. u8 sync = 0;
  996. u8 tslock = 0;
  997. u8 unlock = 0;
  998. struct cxd2841er_priv *priv = fe->demodulator_priv;
  999. *status = 0;
  1000. if (priv->state == STATE_ACTIVE_TC) {
  1001. if (priv->system == SYS_DVBT || priv->system == SYS_DVBT2) {
  1002. ret = cxd2841er_read_status_t_t2(
  1003. priv, &sync, &tslock, &unlock);
  1004. if (ret)
  1005. goto done;
  1006. if (unlock)
  1007. goto done;
  1008. if (sync)
  1009. *status = FE_HAS_SIGNAL |
  1010. FE_HAS_CARRIER |
  1011. FE_HAS_VITERBI |
  1012. FE_HAS_SYNC;
  1013. if (tslock)
  1014. *status |= FE_HAS_LOCK;
  1015. } else if (priv->system == SYS_ISDBT) {
  1016. ret = cxd2841er_read_status_i(
  1017. priv, &sync, &tslock, &unlock);
  1018. if (ret)
  1019. goto done;
  1020. if (unlock)
  1021. goto done;
  1022. if (sync)
  1023. *status = FE_HAS_SIGNAL |
  1024. FE_HAS_CARRIER |
  1025. FE_HAS_VITERBI |
  1026. FE_HAS_SYNC;
  1027. if (tslock)
  1028. *status |= FE_HAS_LOCK;
  1029. } else if (priv->system == SYS_DVBC_ANNEX_A) {
  1030. ret = cxd2841er_read_status_c(priv, &tslock);
  1031. if (ret)
  1032. goto done;
  1033. if (tslock)
  1034. *status = FE_HAS_SIGNAL |
  1035. FE_HAS_CARRIER |
  1036. FE_HAS_VITERBI |
  1037. FE_HAS_SYNC |
  1038. FE_HAS_LOCK;
  1039. }
  1040. }
  1041. done:
  1042. dev_dbg(&priv->i2c->dev, "%s(): status 0x%x\n", __func__, *status);
  1043. return ret;
  1044. }
  1045. static int cxd2841er_get_carrier_offset_s_s2(struct cxd2841er_priv *priv,
  1046. int *offset)
  1047. {
  1048. u8 data[3];
  1049. u8 is_hs_mode;
  1050. s32 cfrl_ctrlval;
  1051. s32 temp_div, temp_q, temp_r;
  1052. if (priv->state != STATE_ACTIVE_S) {
  1053. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  1054. __func__, priv->state);
  1055. return -EINVAL;
  1056. }
  1057. /*
  1058. * Get High Sampling Rate mode
  1059. * slave Bank Addr Bit Signal name
  1060. * <SLV-T> A0h 10h [0] ITRL_LOCK
  1061. */
  1062. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0);
  1063. cxd2841er_read_reg(priv, I2C_SLVT, 0x10, &data[0]);
  1064. if (data[0] & 0x01) {
  1065. /*
  1066. * slave Bank Addr Bit Signal name
  1067. * <SLV-T> A0h 50h [4] IHSMODE
  1068. */
  1069. cxd2841er_read_reg(priv, I2C_SLVT, 0x50, &data[0]);
  1070. is_hs_mode = (data[0] & 0x10 ? 1 : 0);
  1071. } else {
  1072. dev_dbg(&priv->i2c->dev,
  1073. "%s(): unable to detect sampling rate mode\n",
  1074. __func__);
  1075. return -EINVAL;
  1076. }
  1077. /*
  1078. * slave Bank Addr Bit Signal name
  1079. * <SLV-T> A0h 45h [4:0] ICFRL_CTRLVAL[20:16]
  1080. * <SLV-T> A0h 46h [7:0] ICFRL_CTRLVAL[15:8]
  1081. * <SLV-T> A0h 47h [7:0] ICFRL_CTRLVAL[7:0]
  1082. */
  1083. cxd2841er_read_regs(priv, I2C_SLVT, 0x45, data, 3);
  1084. cfrl_ctrlval = sign_extend32((((u32)data[0] & 0x1F) << 16) |
  1085. (((u32)data[1] & 0xFF) << 8) |
  1086. ((u32)data[2] & 0xFF), 20);
  1087. temp_div = (is_hs_mode ? 1048576 : 1572864);
  1088. if (cfrl_ctrlval > 0) {
  1089. temp_q = div_s64_rem(97375LL * cfrl_ctrlval,
  1090. temp_div, &temp_r);
  1091. } else {
  1092. temp_q = div_s64_rem(-97375LL * cfrl_ctrlval,
  1093. temp_div, &temp_r);
  1094. }
  1095. if (temp_r >= temp_div / 2)
  1096. temp_q++;
  1097. if (cfrl_ctrlval > 0)
  1098. temp_q *= -1;
  1099. *offset = temp_q;
  1100. return 0;
  1101. }
  1102. static int cxd2841er_get_carrier_offset_i(struct cxd2841er_priv *priv,
  1103. u32 bandwidth, int *offset)
  1104. {
  1105. u8 data[4];
  1106. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1107. if (priv->state != STATE_ACTIVE_TC) {
  1108. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  1109. __func__, priv->state);
  1110. return -EINVAL;
  1111. }
  1112. if (priv->system != SYS_ISDBT) {
  1113. dev_dbg(&priv->i2c->dev, "%s(): invalid delivery system %d\n",
  1114. __func__, priv->system);
  1115. return -EINVAL;
  1116. }
  1117. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x60);
  1118. cxd2841er_read_regs(priv, I2C_SLVT, 0x4c, data, sizeof(data));
  1119. *offset = -1 * sign_extend32(
  1120. ((u32)(data[0] & 0x1F) << 24) | ((u32)data[1] << 16) |
  1121. ((u32)data[2] << 8) | (u32)data[3], 29);
  1122. switch (bandwidth) {
  1123. case 6000000:
  1124. *offset = -1 * ((*offset) * 8/264);
  1125. break;
  1126. case 7000000:
  1127. *offset = -1 * ((*offset) * 8/231);
  1128. break;
  1129. case 8000000:
  1130. *offset = -1 * ((*offset) * 8/198);
  1131. break;
  1132. default:
  1133. dev_dbg(&priv->i2c->dev, "%s(): invalid bandwidth %d\n",
  1134. __func__, bandwidth);
  1135. return -EINVAL;
  1136. }
  1137. dev_dbg(&priv->i2c->dev, "%s(): bandwidth %d offset %d\n",
  1138. __func__, bandwidth, *offset);
  1139. return 0;
  1140. }
  1141. static int cxd2841er_get_carrier_offset_t(struct cxd2841er_priv *priv,
  1142. u32 bandwidth, int *offset)
  1143. {
  1144. u8 data[4];
  1145. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1146. if (priv->state != STATE_ACTIVE_TC) {
  1147. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  1148. __func__, priv->state);
  1149. return -EINVAL;
  1150. }
  1151. if (priv->system != SYS_DVBT) {
  1152. dev_dbg(&priv->i2c->dev, "%s(): invalid delivery system %d\n",
  1153. __func__, priv->system);
  1154. return -EINVAL;
  1155. }
  1156. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  1157. cxd2841er_read_regs(priv, I2C_SLVT, 0x4c, data, sizeof(data));
  1158. *offset = -1 * sign_extend32(
  1159. ((u32)(data[0] & 0x1F) << 24) | ((u32)data[1] << 16) |
  1160. ((u32)data[2] << 8) | (u32)data[3], 29);
  1161. *offset *= (bandwidth / 1000000);
  1162. *offset /= 235;
  1163. return 0;
  1164. }
  1165. static int cxd2841er_get_carrier_offset_t2(struct cxd2841er_priv *priv,
  1166. u32 bandwidth, int *offset)
  1167. {
  1168. u8 data[4];
  1169. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1170. if (priv->state != STATE_ACTIVE_TC) {
  1171. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  1172. __func__, priv->state);
  1173. return -EINVAL;
  1174. }
  1175. if (priv->system != SYS_DVBT2) {
  1176. dev_dbg(&priv->i2c->dev, "%s(): invalid delivery system %d\n",
  1177. __func__, priv->system);
  1178. return -EINVAL;
  1179. }
  1180. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20);
  1181. cxd2841er_read_regs(priv, I2C_SLVT, 0x4c, data, sizeof(data));
  1182. *offset = -1 * sign_extend32(
  1183. ((u32)(data[0] & 0x0F) << 24) | ((u32)data[1] << 16) |
  1184. ((u32)data[2] << 8) | (u32)data[3], 27);
  1185. switch (bandwidth) {
  1186. case 1712000:
  1187. *offset /= 582;
  1188. break;
  1189. case 5000000:
  1190. case 6000000:
  1191. case 7000000:
  1192. case 8000000:
  1193. *offset *= (bandwidth / 1000000);
  1194. *offset /= 940;
  1195. break;
  1196. default:
  1197. dev_dbg(&priv->i2c->dev, "%s(): invalid bandwidth %d\n",
  1198. __func__, bandwidth);
  1199. return -EINVAL;
  1200. }
  1201. return 0;
  1202. }
  1203. static int cxd2841er_get_carrier_offset_c(struct cxd2841er_priv *priv,
  1204. int *offset)
  1205. {
  1206. u8 data[2];
  1207. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1208. if (priv->state != STATE_ACTIVE_TC) {
  1209. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  1210. __func__, priv->state);
  1211. return -EINVAL;
  1212. }
  1213. if (priv->system != SYS_DVBC_ANNEX_A) {
  1214. dev_dbg(&priv->i2c->dev, "%s(): invalid delivery system %d\n",
  1215. __func__, priv->system);
  1216. return -EINVAL;
  1217. }
  1218. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40);
  1219. cxd2841er_read_regs(priv, I2C_SLVT, 0x15, data, sizeof(data));
  1220. *offset = div_s64(41000LL * sign_extend32((((u32)data[0] & 0x3f) << 8)
  1221. | (u32)data[1], 13), 16384);
  1222. return 0;
  1223. }
  1224. static int cxd2841er_read_packet_errors_c(
  1225. struct cxd2841er_priv *priv, u32 *penum)
  1226. {
  1227. u8 data[3];
  1228. *penum = 0;
  1229. if (priv->state != STATE_ACTIVE_TC) {
  1230. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  1231. __func__, priv->state);
  1232. return -EINVAL;
  1233. }
  1234. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40);
  1235. cxd2841er_read_regs(priv, I2C_SLVT, 0xea, data, sizeof(data));
  1236. if (data[2] & 0x01)
  1237. *penum = ((u32)data[0] << 8) | (u32)data[1];
  1238. return 0;
  1239. }
  1240. static int cxd2841er_read_packet_errors_t(
  1241. struct cxd2841er_priv *priv, u32 *penum)
  1242. {
  1243. u8 data[3];
  1244. *penum = 0;
  1245. if (priv->state != STATE_ACTIVE_TC) {
  1246. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  1247. __func__, priv->state);
  1248. return -EINVAL;
  1249. }
  1250. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  1251. cxd2841er_read_regs(priv, I2C_SLVT, 0xea, data, sizeof(data));
  1252. if (data[2] & 0x01)
  1253. *penum = ((u32)data[0] << 8) | (u32)data[1];
  1254. return 0;
  1255. }
  1256. static int cxd2841er_read_packet_errors_t2(
  1257. struct cxd2841er_priv *priv, u32 *penum)
  1258. {
  1259. u8 data[3];
  1260. *penum = 0;
  1261. if (priv->state != STATE_ACTIVE_TC) {
  1262. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  1263. __func__, priv->state);
  1264. return -EINVAL;
  1265. }
  1266. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x24);
  1267. cxd2841er_read_regs(priv, I2C_SLVT, 0xfd, data, sizeof(data));
  1268. if (data[0] & 0x01)
  1269. *penum = ((u32)data[1] << 8) | (u32)data[2];
  1270. return 0;
  1271. }
  1272. static int cxd2841er_read_packet_errors_i(
  1273. struct cxd2841er_priv *priv, u32 *penum)
  1274. {
  1275. u8 data[2];
  1276. *penum = 0;
  1277. if (priv->state != STATE_ACTIVE_TC) {
  1278. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  1279. __func__, priv->state);
  1280. return -EINVAL;
  1281. }
  1282. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x60);
  1283. cxd2841er_read_regs(priv, I2C_SLVT, 0xA1, data, 1);
  1284. if (!(data[0] & 0x01))
  1285. return 0;
  1286. /* Layer A */
  1287. cxd2841er_read_regs(priv, I2C_SLVT, 0xA2, data, sizeof(data));
  1288. *penum = ((u32)data[0] << 8) | (u32)data[1];
  1289. /* Layer B */
  1290. cxd2841er_read_regs(priv, I2C_SLVT, 0xA4, data, sizeof(data));
  1291. *penum += ((u32)data[0] << 8) | (u32)data[1];
  1292. /* Layer C */
  1293. cxd2841er_read_regs(priv, I2C_SLVT, 0xA6, data, sizeof(data));
  1294. *penum += ((u32)data[0] << 8) | (u32)data[1];
  1295. return 0;
  1296. }
  1297. static int cxd2841er_read_ber_c(struct cxd2841er_priv *priv,
  1298. u32 *bit_error, u32 *bit_count)
  1299. {
  1300. u8 data[3];
  1301. u32 bit_err, period_exp;
  1302. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1303. if (priv->state != STATE_ACTIVE_TC) {
  1304. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  1305. __func__, priv->state);
  1306. return -EINVAL;
  1307. }
  1308. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40);
  1309. cxd2841er_read_regs(priv, I2C_SLVT, 0x62, data, sizeof(data));
  1310. if (!(data[0] & 0x80)) {
  1311. dev_dbg(&priv->i2c->dev,
  1312. "%s(): no valid BER data\n", __func__);
  1313. return -EINVAL;
  1314. }
  1315. bit_err = ((u32)(data[0] & 0x3f) << 16) |
  1316. ((u32)data[1] << 8) |
  1317. (u32)data[2];
  1318. cxd2841er_read_reg(priv, I2C_SLVT, 0x60, data);
  1319. period_exp = data[0] & 0x1f;
  1320. if ((period_exp <= 11) && (bit_err > (1 << period_exp) * 204 * 8)) {
  1321. dev_dbg(&priv->i2c->dev,
  1322. "%s(): period_exp(%u) or bit_err(%u) not in range. no valid BER data\n",
  1323. __func__, period_exp, bit_err);
  1324. return -EINVAL;
  1325. }
  1326. dev_dbg(&priv->i2c->dev,
  1327. "%s(): period_exp(%u) or bit_err(%u) count=%d\n",
  1328. __func__, period_exp, bit_err,
  1329. ((1 << period_exp) * 204 * 8));
  1330. *bit_error = bit_err;
  1331. *bit_count = ((1 << period_exp) * 204 * 8);
  1332. return 0;
  1333. }
  1334. static int cxd2841er_read_ber_i(struct cxd2841er_priv *priv,
  1335. u32 *bit_error, u32 *bit_count)
  1336. {
  1337. u8 data[3];
  1338. u8 pktnum[2];
  1339. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1340. if (priv->state != STATE_ACTIVE_TC) {
  1341. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  1342. __func__, priv->state);
  1343. return -EINVAL;
  1344. }
  1345. cxd2841er_freeze_regs(priv);
  1346. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x60);
  1347. cxd2841er_read_regs(priv, I2C_SLVT, 0x5B, pktnum, sizeof(pktnum));
  1348. cxd2841er_read_regs(priv, I2C_SLVT, 0x16, data, sizeof(data));
  1349. cxd2841er_unfreeze_regs(priv);
  1350. if (!pktnum[0] && !pktnum[1]) {
  1351. dev_dbg(&priv->i2c->dev,
  1352. "%s(): no valid BER data\n", __func__);
  1353. return -EINVAL;
  1354. }
  1355. *bit_error = ((u32)(data[0] & 0x7F) << 16) |
  1356. ((u32)data[1] << 8) | data[2];
  1357. *bit_count = ((((u32)pktnum[0] << 8) | pktnum[1]) * 204 * 8);
  1358. dev_dbg(&priv->i2c->dev, "%s(): bit_error=%u bit_count=%u\n",
  1359. __func__, *bit_error, *bit_count);
  1360. return 0;
  1361. }
  1362. static int cxd2841er_mon_read_ber_s(struct cxd2841er_priv *priv,
  1363. u32 *bit_error, u32 *bit_count)
  1364. {
  1365. u8 data[11];
  1366. /* Set SLV-T Bank : 0xA0 */
  1367. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0);
  1368. /*
  1369. * slave Bank Addr Bit Signal name
  1370. * <SLV-T> A0h 35h [0] IFVBER_VALID
  1371. * <SLV-T> A0h 36h [5:0] IFVBER_BITERR[21:16]
  1372. * <SLV-T> A0h 37h [7:0] IFVBER_BITERR[15:8]
  1373. * <SLV-T> A0h 38h [7:0] IFVBER_BITERR[7:0]
  1374. * <SLV-T> A0h 3Dh [5:0] IFVBER_BITNUM[21:16]
  1375. * <SLV-T> A0h 3Eh [7:0] IFVBER_BITNUM[15:8]
  1376. * <SLV-T> A0h 3Fh [7:0] IFVBER_BITNUM[7:0]
  1377. */
  1378. cxd2841er_read_regs(priv, I2C_SLVT, 0x35, data, 11);
  1379. if (data[0] & 0x01) {
  1380. *bit_error = ((u32)(data[1] & 0x3F) << 16) |
  1381. ((u32)(data[2] & 0xFF) << 8) |
  1382. (u32)(data[3] & 0xFF);
  1383. *bit_count = ((u32)(data[8] & 0x3F) << 16) |
  1384. ((u32)(data[9] & 0xFF) << 8) |
  1385. (u32)(data[10] & 0xFF);
  1386. if ((*bit_count == 0) || (*bit_error > *bit_count)) {
  1387. dev_dbg(&priv->i2c->dev,
  1388. "%s(): invalid bit_error %d, bit_count %d\n",
  1389. __func__, *bit_error, *bit_count);
  1390. return -EINVAL;
  1391. }
  1392. return 0;
  1393. }
  1394. dev_dbg(&priv->i2c->dev, "%s(): no data available\n", __func__);
  1395. return -EINVAL;
  1396. }
  1397. static int cxd2841er_mon_read_ber_s2(struct cxd2841er_priv *priv,
  1398. u32 *bit_error, u32 *bit_count)
  1399. {
  1400. u8 data[5];
  1401. u32 period;
  1402. /* Set SLV-T Bank : 0xB2 */
  1403. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xb2);
  1404. /*
  1405. * slave Bank Addr Bit Signal name
  1406. * <SLV-T> B2h 30h [0] IFLBER_VALID
  1407. * <SLV-T> B2h 31h [3:0] IFLBER_BITERR[27:24]
  1408. * <SLV-T> B2h 32h [7:0] IFLBER_BITERR[23:16]
  1409. * <SLV-T> B2h 33h [7:0] IFLBER_BITERR[15:8]
  1410. * <SLV-T> B2h 34h [7:0] IFLBER_BITERR[7:0]
  1411. */
  1412. cxd2841er_read_regs(priv, I2C_SLVT, 0x30, data, 5);
  1413. if (data[0] & 0x01) {
  1414. /* Bit error count */
  1415. *bit_error = ((u32)(data[1] & 0x0F) << 24) |
  1416. ((u32)(data[2] & 0xFF) << 16) |
  1417. ((u32)(data[3] & 0xFF) << 8) |
  1418. (u32)(data[4] & 0xFF);
  1419. /* Set SLV-T Bank : 0xA0 */
  1420. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0);
  1421. cxd2841er_read_reg(priv, I2C_SLVT, 0x7a, data);
  1422. /* Measurement period */
  1423. period = (u32)(1 << (data[0] & 0x0F));
  1424. if (period == 0) {
  1425. dev_dbg(&priv->i2c->dev,
  1426. "%s(): period is 0\n", __func__);
  1427. return -EINVAL;
  1428. }
  1429. if (*bit_error > (period * 64800)) {
  1430. dev_dbg(&priv->i2c->dev,
  1431. "%s(): invalid bit_err 0x%x period 0x%x\n",
  1432. __func__, *bit_error, period);
  1433. return -EINVAL;
  1434. }
  1435. *bit_count = period * 64800;
  1436. return 0;
  1437. } else {
  1438. dev_dbg(&priv->i2c->dev,
  1439. "%s(): no data available\n", __func__);
  1440. }
  1441. return -EINVAL;
  1442. }
  1443. static int cxd2841er_read_ber_t2(struct cxd2841er_priv *priv,
  1444. u32 *bit_error, u32 *bit_count)
  1445. {
  1446. u8 data[4];
  1447. u32 period_exp, n_ldpc;
  1448. if (priv->state != STATE_ACTIVE_TC) {
  1449. dev_dbg(&priv->i2c->dev,
  1450. "%s(): invalid state %d\n", __func__, priv->state);
  1451. return -EINVAL;
  1452. }
  1453. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20);
  1454. cxd2841er_read_regs(priv, I2C_SLVT, 0x39, data, sizeof(data));
  1455. if (!(data[0] & 0x10)) {
  1456. dev_dbg(&priv->i2c->dev,
  1457. "%s(): no valid BER data\n", __func__);
  1458. return -EINVAL;
  1459. }
  1460. *bit_error = ((u32)(data[0] & 0x0f) << 24) |
  1461. ((u32)data[1] << 16) |
  1462. ((u32)data[2] << 8) |
  1463. (u32)data[3];
  1464. cxd2841er_read_reg(priv, I2C_SLVT, 0x6f, data);
  1465. period_exp = data[0] & 0x0f;
  1466. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x22);
  1467. cxd2841er_read_reg(priv, I2C_SLVT, 0x5e, data);
  1468. n_ldpc = ((data[0] & 0x03) == 0 ? 16200 : 64800);
  1469. if (*bit_error > ((1U << period_exp) * n_ldpc)) {
  1470. dev_dbg(&priv->i2c->dev,
  1471. "%s(): invalid BER value\n", __func__);
  1472. return -EINVAL;
  1473. }
  1474. /*
  1475. * FIXME: the right thing would be to return bit_error untouched,
  1476. * but, as we don't know the scale returned by the counters, let's
  1477. * at least preserver BER = bit_error/bit_count.
  1478. */
  1479. if (period_exp >= 4) {
  1480. *bit_count = (1U << (period_exp - 4)) * (n_ldpc / 200);
  1481. *bit_error *= 3125ULL;
  1482. } else {
  1483. *bit_count = (1U << period_exp) * (n_ldpc / 200);
  1484. *bit_error *= 50000ULL;
  1485. }
  1486. return 0;
  1487. }
  1488. static int cxd2841er_read_ber_t(struct cxd2841er_priv *priv,
  1489. u32 *bit_error, u32 *bit_count)
  1490. {
  1491. u8 data[2];
  1492. u32 period;
  1493. if (priv->state != STATE_ACTIVE_TC) {
  1494. dev_dbg(&priv->i2c->dev,
  1495. "%s(): invalid state %d\n", __func__, priv->state);
  1496. return -EINVAL;
  1497. }
  1498. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  1499. cxd2841er_read_reg(priv, I2C_SLVT, 0x39, data);
  1500. if (!(data[0] & 0x01)) {
  1501. dev_dbg(&priv->i2c->dev,
  1502. "%s(): no valid BER data\n", __func__);
  1503. return 0;
  1504. }
  1505. cxd2841er_read_regs(priv, I2C_SLVT, 0x22, data, sizeof(data));
  1506. *bit_error = ((u32)data[0] << 8) | (u32)data[1];
  1507. cxd2841er_read_reg(priv, I2C_SLVT, 0x6f, data);
  1508. period = ((data[0] & 0x07) == 0) ? 256 : (4096 << (data[0] & 0x07));
  1509. /*
  1510. * FIXME: the right thing would be to return bit_error untouched,
  1511. * but, as we don't know the scale returned by the counters, let's
  1512. * at least preserver BER = bit_error/bit_count.
  1513. */
  1514. *bit_count = period / 128;
  1515. *bit_error *= 78125ULL;
  1516. return 0;
  1517. }
  1518. static int cxd2841er_freeze_regs(struct cxd2841er_priv *priv)
  1519. {
  1520. /*
  1521. * Freeze registers: ensure multiple separate register reads
  1522. * are from the same snapshot
  1523. */
  1524. cxd2841er_write_reg(priv, I2C_SLVT, 0x01, 0x01);
  1525. return 0;
  1526. }
  1527. static int cxd2841er_unfreeze_regs(struct cxd2841er_priv *priv)
  1528. {
  1529. /*
  1530. * un-freeze registers
  1531. */
  1532. cxd2841er_write_reg(priv, I2C_SLVT, 0x01, 0x00);
  1533. return 0;
  1534. }
  1535. static u32 cxd2841er_dvbs_read_snr(struct cxd2841er_priv *priv,
  1536. u8 delsys, u32 *snr)
  1537. {
  1538. u8 data[3];
  1539. u32 res = 0, value;
  1540. int min_index, max_index, index;
  1541. static const struct cxd2841er_cnr_data *cn_data;
  1542. cxd2841er_freeze_regs(priv);
  1543. /* Set SLV-T Bank : 0xA1 */
  1544. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa1);
  1545. /*
  1546. * slave Bank Addr Bit Signal name
  1547. * <SLV-T> A1h 10h [0] ICPM_QUICKRDY
  1548. * <SLV-T> A1h 11h [4:0] ICPM_QUICKCNDT[12:8]
  1549. * <SLV-T> A1h 12h [7:0] ICPM_QUICKCNDT[7:0]
  1550. */
  1551. cxd2841er_read_regs(priv, I2C_SLVT, 0x10, data, 3);
  1552. cxd2841er_unfreeze_regs(priv);
  1553. if (data[0] & 0x01) {
  1554. value = ((u32)(data[1] & 0x1F) << 8) | (u32)(data[2] & 0xFF);
  1555. min_index = 0;
  1556. if (delsys == SYS_DVBS) {
  1557. cn_data = s_cn_data;
  1558. max_index = ARRAY_SIZE(s_cn_data) - 1;
  1559. } else {
  1560. cn_data = s2_cn_data;
  1561. max_index = ARRAY_SIZE(s2_cn_data) - 1;
  1562. }
  1563. if (value >= cn_data[min_index].value) {
  1564. res = cn_data[min_index].cnr_x1000;
  1565. goto done;
  1566. }
  1567. if (value <= cn_data[max_index].value) {
  1568. res = cn_data[max_index].cnr_x1000;
  1569. goto done;
  1570. }
  1571. while ((max_index - min_index) > 1) {
  1572. index = (max_index + min_index) / 2;
  1573. if (value == cn_data[index].value) {
  1574. res = cn_data[index].cnr_x1000;
  1575. goto done;
  1576. } else if (value > cn_data[index].value)
  1577. max_index = index;
  1578. else
  1579. min_index = index;
  1580. if ((max_index - min_index) <= 1) {
  1581. if (value == cn_data[max_index].value) {
  1582. res = cn_data[max_index].cnr_x1000;
  1583. goto done;
  1584. } else {
  1585. res = cn_data[min_index].cnr_x1000;
  1586. goto done;
  1587. }
  1588. }
  1589. }
  1590. } else {
  1591. dev_dbg(&priv->i2c->dev,
  1592. "%s(): no data available\n", __func__);
  1593. return -EINVAL;
  1594. }
  1595. done:
  1596. *snr = res;
  1597. return 0;
  1598. }
  1599. static uint32_t sony_log(uint32_t x)
  1600. {
  1601. return (((10000>>8)*(intlog2(x)>>16) + LOG2_E_100X/2)/LOG2_E_100X);
  1602. }
  1603. static int cxd2841er_read_snr_c(struct cxd2841er_priv *priv, u32 *snr)
  1604. {
  1605. u32 reg;
  1606. u8 data[2];
  1607. enum sony_dvbc_constellation_t qam = SONY_DVBC_CONSTELLATION_16QAM;
  1608. *snr = 0;
  1609. if (priv->state != STATE_ACTIVE_TC) {
  1610. dev_dbg(&priv->i2c->dev,
  1611. "%s(): invalid state %d\n",
  1612. __func__, priv->state);
  1613. return -EINVAL;
  1614. }
  1615. cxd2841er_freeze_regs(priv);
  1616. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40);
  1617. cxd2841er_read_regs(priv, I2C_SLVT, 0x19, data, 1);
  1618. qam = (enum sony_dvbc_constellation_t) (data[0] & 0x07);
  1619. cxd2841er_read_regs(priv, I2C_SLVT, 0x4C, data, 2);
  1620. cxd2841er_unfreeze_regs(priv);
  1621. reg = ((u32)(data[0]&0x1f) << 8) | (u32)data[1];
  1622. if (reg == 0) {
  1623. dev_dbg(&priv->i2c->dev,
  1624. "%s(): reg value out of range\n", __func__);
  1625. return 0;
  1626. }
  1627. switch (qam) {
  1628. case SONY_DVBC_CONSTELLATION_16QAM:
  1629. case SONY_DVBC_CONSTELLATION_64QAM:
  1630. case SONY_DVBC_CONSTELLATION_256QAM:
  1631. /* SNR(dB) = -9.50 * ln(IREG_SNR_ESTIMATE / (24320)) */
  1632. if (reg < 126)
  1633. reg = 126;
  1634. *snr = -95 * (int32_t)sony_log(reg) + 95941;
  1635. break;
  1636. case SONY_DVBC_CONSTELLATION_32QAM:
  1637. case SONY_DVBC_CONSTELLATION_128QAM:
  1638. /* SNR(dB) = -8.75 * ln(IREG_SNR_ESTIMATE / (20800)) */
  1639. if (reg < 69)
  1640. reg = 69;
  1641. *snr = -88 * (int32_t)sony_log(reg) + 86999;
  1642. break;
  1643. default:
  1644. return -EINVAL;
  1645. }
  1646. return 0;
  1647. }
  1648. static int cxd2841er_read_snr_t(struct cxd2841er_priv *priv, u32 *snr)
  1649. {
  1650. u32 reg;
  1651. u8 data[2];
  1652. *snr = 0;
  1653. if (priv->state != STATE_ACTIVE_TC) {
  1654. dev_dbg(&priv->i2c->dev,
  1655. "%s(): invalid state %d\n", __func__, priv->state);
  1656. return -EINVAL;
  1657. }
  1658. cxd2841er_freeze_regs(priv);
  1659. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  1660. cxd2841er_read_regs(priv, I2C_SLVT, 0x28, data, sizeof(data));
  1661. cxd2841er_unfreeze_regs(priv);
  1662. reg = ((u32)data[0] << 8) | (u32)data[1];
  1663. if (reg == 0) {
  1664. dev_dbg(&priv->i2c->dev,
  1665. "%s(): reg value out of range\n", __func__);
  1666. return 0;
  1667. }
  1668. if (reg > 4996)
  1669. reg = 4996;
  1670. *snr = 100 * ((INTLOG10X100(reg) - INTLOG10X100(5350 - reg)) + 285);
  1671. return 0;
  1672. }
  1673. static int cxd2841er_read_snr_t2(struct cxd2841er_priv *priv, u32 *snr)
  1674. {
  1675. u32 reg;
  1676. u8 data[2];
  1677. *snr = 0;
  1678. if (priv->state != STATE_ACTIVE_TC) {
  1679. dev_dbg(&priv->i2c->dev,
  1680. "%s(): invalid state %d\n", __func__, priv->state);
  1681. return -EINVAL;
  1682. }
  1683. cxd2841er_freeze_regs(priv);
  1684. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20);
  1685. cxd2841er_read_regs(priv, I2C_SLVT, 0x28, data, sizeof(data));
  1686. cxd2841er_unfreeze_regs(priv);
  1687. reg = ((u32)data[0] << 8) | (u32)data[1];
  1688. if (reg == 0) {
  1689. dev_dbg(&priv->i2c->dev,
  1690. "%s(): reg value out of range\n", __func__);
  1691. return 0;
  1692. }
  1693. if (reg > 10876)
  1694. reg = 10876;
  1695. *snr = 100 * ((INTLOG10X100(reg) - INTLOG10X100(12600 - reg)) + 320);
  1696. return 0;
  1697. }
  1698. static int cxd2841er_read_snr_i(struct cxd2841er_priv *priv, u32 *snr)
  1699. {
  1700. u32 reg;
  1701. u8 data[2];
  1702. *snr = 0;
  1703. if (priv->state != STATE_ACTIVE_TC) {
  1704. dev_dbg(&priv->i2c->dev,
  1705. "%s(): invalid state %d\n", __func__,
  1706. priv->state);
  1707. return -EINVAL;
  1708. }
  1709. cxd2841er_freeze_regs(priv);
  1710. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x60);
  1711. cxd2841er_read_regs(priv, I2C_SLVT, 0x28, data, sizeof(data));
  1712. cxd2841er_unfreeze_regs(priv);
  1713. reg = ((u32)data[0] << 8) | (u32)data[1];
  1714. if (reg == 0) {
  1715. dev_dbg(&priv->i2c->dev,
  1716. "%s(): reg value out of range\n", __func__);
  1717. return 0;
  1718. }
  1719. *snr = 10000 * (intlog10(reg) >> 24) - 9031;
  1720. return 0;
  1721. }
  1722. static u16 cxd2841er_read_agc_gain_c(struct cxd2841er_priv *priv,
  1723. u8 delsys)
  1724. {
  1725. u8 data[2];
  1726. cxd2841er_write_reg(
  1727. priv, I2C_SLVT, 0x00, 0x40);
  1728. cxd2841er_read_regs(priv, I2C_SLVT, 0x49, data, 2);
  1729. dev_dbg(&priv->i2c->dev,
  1730. "%s(): AGC value=%u\n",
  1731. __func__, (((u16)data[0] & 0x0F) << 8) |
  1732. (u16)(data[1] & 0xFF));
  1733. return ((((u16)data[0] & 0x0F) << 8) | (u16)(data[1] & 0xFF)) << 4;
  1734. }
  1735. static u16 cxd2841er_read_agc_gain_t_t2(struct cxd2841er_priv *priv,
  1736. u8 delsys)
  1737. {
  1738. u8 data[2];
  1739. cxd2841er_write_reg(
  1740. priv, I2C_SLVT, 0x00, (delsys == SYS_DVBT ? 0x10 : 0x20));
  1741. cxd2841er_read_regs(priv, I2C_SLVT, 0x26, data, 2);
  1742. dev_dbg(&priv->i2c->dev,
  1743. "%s(): AGC value=%u\n",
  1744. __func__, (((u16)data[0] & 0x0F) << 8) |
  1745. (u16)(data[1] & 0xFF));
  1746. return ((((u16)data[0] & 0x0F) << 8) | (u16)(data[1] & 0xFF)) << 4;
  1747. }
  1748. static u16 cxd2841er_read_agc_gain_i(struct cxd2841er_priv *priv,
  1749. u8 delsys)
  1750. {
  1751. u8 data[2];
  1752. cxd2841er_write_reg(
  1753. priv, I2C_SLVT, 0x00, 0x60);
  1754. cxd2841er_read_regs(priv, I2C_SLVT, 0x26, data, 2);
  1755. dev_dbg(&priv->i2c->dev,
  1756. "%s(): AGC value=%u\n",
  1757. __func__, (((u16)data[0] & 0x0F) << 8) |
  1758. (u16)(data[1] & 0xFF));
  1759. return ((((u16)data[0] & 0x0F) << 8) | (u16)(data[1] & 0xFF)) << 4;
  1760. }
  1761. static u16 cxd2841er_read_agc_gain_s(struct cxd2841er_priv *priv)
  1762. {
  1763. u8 data[2];
  1764. /* Set SLV-T Bank : 0xA0 */
  1765. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0);
  1766. /*
  1767. * slave Bank Addr Bit Signal name
  1768. * <SLV-T> A0h 1Fh [4:0] IRFAGC_GAIN[12:8]
  1769. * <SLV-T> A0h 20h [7:0] IRFAGC_GAIN[7:0]
  1770. */
  1771. cxd2841er_read_regs(priv, I2C_SLVT, 0x1f, data, 2);
  1772. return ((((u16)data[0] & 0x1F) << 8) | (u16)(data[1] & 0xFF)) << 3;
  1773. }
  1774. static void cxd2841er_read_ber(struct dvb_frontend *fe)
  1775. {
  1776. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  1777. struct cxd2841er_priv *priv = fe->demodulator_priv;
  1778. u32 ret, bit_error = 0, bit_count = 0;
  1779. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1780. switch (p->delivery_system) {
  1781. case SYS_DVBC_ANNEX_A:
  1782. case SYS_DVBC_ANNEX_B:
  1783. case SYS_DVBC_ANNEX_C:
  1784. ret = cxd2841er_read_ber_c(priv, &bit_error, &bit_count);
  1785. break;
  1786. case SYS_ISDBT:
  1787. ret = cxd2841er_read_ber_i(priv, &bit_error, &bit_count);
  1788. break;
  1789. case SYS_DVBS:
  1790. ret = cxd2841er_mon_read_ber_s(priv, &bit_error, &bit_count);
  1791. break;
  1792. case SYS_DVBS2:
  1793. ret = cxd2841er_mon_read_ber_s2(priv, &bit_error, &bit_count);
  1794. break;
  1795. case SYS_DVBT:
  1796. ret = cxd2841er_read_ber_t(priv, &bit_error, &bit_count);
  1797. break;
  1798. case SYS_DVBT2:
  1799. ret = cxd2841er_read_ber_t2(priv, &bit_error, &bit_count);
  1800. break;
  1801. default:
  1802. p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1803. p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1804. return;
  1805. }
  1806. if (!ret) {
  1807. p->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
  1808. p->post_bit_error.stat[0].uvalue += bit_error;
  1809. p->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
  1810. p->post_bit_count.stat[0].uvalue += bit_count;
  1811. } else {
  1812. p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1813. p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1814. }
  1815. }
  1816. static void cxd2841er_read_signal_strength(struct dvb_frontend *fe)
  1817. {
  1818. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  1819. struct cxd2841er_priv *priv = fe->demodulator_priv;
  1820. s32 strength;
  1821. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1822. switch (p->delivery_system) {
  1823. case SYS_DVBT:
  1824. case SYS_DVBT2:
  1825. strength = cxd2841er_read_agc_gain_t_t2(priv,
  1826. p->delivery_system);
  1827. p->strength.stat[0].scale = FE_SCALE_DECIBEL;
  1828. /* Formula was empirically determinated @ 410 MHz */
  1829. p->strength.stat[0].uvalue = strength * 366 / 100 - 89520;
  1830. break; /* Code moved out of the function */
  1831. case SYS_DVBC_ANNEX_A:
  1832. case SYS_DVBC_ANNEX_B:
  1833. case SYS_DVBC_ANNEX_C:
  1834. strength = cxd2841er_read_agc_gain_c(priv,
  1835. p->delivery_system);
  1836. p->strength.stat[0].scale = FE_SCALE_DECIBEL;
  1837. /*
  1838. * Formula was empirically determinated via linear regression,
  1839. * using frequencies: 175 MHz, 410 MHz and 800 MHz, and a
  1840. * stream modulated with QAM64
  1841. */
  1842. p->strength.stat[0].uvalue = strength * 4045 / 1000 - 85224;
  1843. break;
  1844. case SYS_ISDBT:
  1845. strength = cxd2841er_read_agc_gain_i(priv, p->delivery_system);
  1846. p->strength.stat[0].scale = FE_SCALE_DECIBEL;
  1847. /*
  1848. * Formula was empirically determinated via linear regression,
  1849. * using frequencies: 175 MHz, 410 MHz and 800 MHz.
  1850. */
  1851. p->strength.stat[0].uvalue = strength * 3775 / 1000 - 90185;
  1852. break;
  1853. case SYS_DVBS:
  1854. case SYS_DVBS2:
  1855. strength = 65535 - cxd2841er_read_agc_gain_s(priv);
  1856. p->strength.stat[0].scale = FE_SCALE_RELATIVE;
  1857. p->strength.stat[0].uvalue = strength;
  1858. break;
  1859. default:
  1860. p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1861. break;
  1862. }
  1863. }
  1864. static void cxd2841er_read_snr(struct dvb_frontend *fe)
  1865. {
  1866. u32 tmp = 0;
  1867. int ret = 0;
  1868. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  1869. struct cxd2841er_priv *priv = fe->demodulator_priv;
  1870. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1871. switch (p->delivery_system) {
  1872. case SYS_DVBC_ANNEX_A:
  1873. case SYS_DVBC_ANNEX_B:
  1874. case SYS_DVBC_ANNEX_C:
  1875. ret = cxd2841er_read_snr_c(priv, &tmp);
  1876. break;
  1877. case SYS_DVBT:
  1878. ret = cxd2841er_read_snr_t(priv, &tmp);
  1879. break;
  1880. case SYS_DVBT2:
  1881. ret = cxd2841er_read_snr_t2(priv, &tmp);
  1882. break;
  1883. case SYS_ISDBT:
  1884. ret = cxd2841er_read_snr_i(priv, &tmp);
  1885. break;
  1886. case SYS_DVBS:
  1887. case SYS_DVBS2:
  1888. ret = cxd2841er_dvbs_read_snr(priv, p->delivery_system, &tmp);
  1889. break;
  1890. default:
  1891. dev_dbg(&priv->i2c->dev, "%s(): unknown delivery system %d\n",
  1892. __func__, p->delivery_system);
  1893. p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1894. return;
  1895. }
  1896. dev_dbg(&priv->i2c->dev, "%s(): snr=%d\n",
  1897. __func__, (int32_t)tmp);
  1898. if (!ret) {
  1899. p->cnr.stat[0].scale = FE_SCALE_DECIBEL;
  1900. p->cnr.stat[0].svalue = tmp;
  1901. } else {
  1902. p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1903. }
  1904. }
  1905. static void cxd2841er_read_ucblocks(struct dvb_frontend *fe)
  1906. {
  1907. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  1908. struct cxd2841er_priv *priv = fe->demodulator_priv;
  1909. u32 ucblocks = 0;
  1910. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1911. switch (p->delivery_system) {
  1912. case SYS_DVBC_ANNEX_A:
  1913. case SYS_DVBC_ANNEX_B:
  1914. case SYS_DVBC_ANNEX_C:
  1915. cxd2841er_read_packet_errors_c(priv, &ucblocks);
  1916. break;
  1917. case SYS_DVBT:
  1918. cxd2841er_read_packet_errors_t(priv, &ucblocks);
  1919. break;
  1920. case SYS_DVBT2:
  1921. cxd2841er_read_packet_errors_t2(priv, &ucblocks);
  1922. break;
  1923. case SYS_ISDBT:
  1924. cxd2841er_read_packet_errors_i(priv, &ucblocks);
  1925. break;
  1926. default:
  1927. p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1928. return;
  1929. }
  1930. dev_dbg(&priv->i2c->dev, "%s() ucblocks=%u\n", __func__, ucblocks);
  1931. p->block_error.stat[0].scale = FE_SCALE_COUNTER;
  1932. p->block_error.stat[0].uvalue = ucblocks;
  1933. }
  1934. static int cxd2841er_dvbt2_set_profile(
  1935. struct cxd2841er_priv *priv, enum cxd2841er_dvbt2_profile_t profile)
  1936. {
  1937. u8 tune_mode;
  1938. u8 seq_not2d_time;
  1939. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  1940. switch (profile) {
  1941. case DVBT2_PROFILE_BASE:
  1942. tune_mode = 0x01;
  1943. /* Set early unlock time */
  1944. seq_not2d_time = (priv->xtal == SONY_XTAL_24000)?0x0E:0x0C;
  1945. break;
  1946. case DVBT2_PROFILE_LITE:
  1947. tune_mode = 0x05;
  1948. /* Set early unlock time */
  1949. seq_not2d_time = (priv->xtal == SONY_XTAL_24000)?0x2E:0x28;
  1950. break;
  1951. case DVBT2_PROFILE_ANY:
  1952. tune_mode = 0x00;
  1953. /* Set early unlock time */
  1954. seq_not2d_time = (priv->xtal == SONY_XTAL_24000)?0x2E:0x28;
  1955. break;
  1956. default:
  1957. return -EINVAL;
  1958. }
  1959. /* Set SLV-T Bank : 0x2E */
  1960. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2e);
  1961. /* Set profile and tune mode */
  1962. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x10, tune_mode, 0x07);
  1963. /* Set SLV-T Bank : 0x2B */
  1964. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2b);
  1965. /* Set early unlock detection time */
  1966. cxd2841er_write_reg(priv, I2C_SLVT, 0x9d, seq_not2d_time);
  1967. return 0;
  1968. }
  1969. static int cxd2841er_dvbt2_set_plp_config(struct cxd2841er_priv *priv,
  1970. u8 is_auto, u8 plp_id)
  1971. {
  1972. if (is_auto) {
  1973. dev_dbg(&priv->i2c->dev,
  1974. "%s() using auto PLP selection\n", __func__);
  1975. } else {
  1976. dev_dbg(&priv->i2c->dev,
  1977. "%s() using manual PLP selection, ID %d\n",
  1978. __func__, plp_id);
  1979. }
  1980. /* Set SLV-T Bank : 0x23 */
  1981. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x23);
  1982. if (!is_auto) {
  1983. /* Manual PLP selection mode. Set the data PLP Id. */
  1984. cxd2841er_write_reg(priv, I2C_SLVT, 0xaf, plp_id);
  1985. }
  1986. /* Auto PLP select (Scanning mode = 0x00). Data PLP select = 0x01. */
  1987. cxd2841er_write_reg(priv, I2C_SLVT, 0xad, (is_auto ? 0x00 : 0x01));
  1988. return 0;
  1989. }
  1990. static int cxd2841er_sleep_tc_to_active_t2_band(struct cxd2841er_priv *priv,
  1991. u32 bandwidth)
  1992. {
  1993. u32 iffreq, ifhz;
  1994. u8 data[MAX_WRITE_REGSIZE];
  1995. static const uint8_t nominalRate8bw[3][5] = {
  1996. /* TRCG Nominal Rate [37:0] */
  1997. {0x11, 0xF0, 0x00, 0x00, 0x00}, /* 20.5MHz XTal */
  1998. {0x15, 0x00, 0x00, 0x00, 0x00}, /* 24MHz XTal */
  1999. {0x11, 0xF0, 0x00, 0x00, 0x00} /* 41MHz XTal */
  2000. };
  2001. static const uint8_t nominalRate7bw[3][5] = {
  2002. /* TRCG Nominal Rate [37:0] */
  2003. {0x14, 0x80, 0x00, 0x00, 0x00}, /* 20.5MHz XTal */
  2004. {0x18, 0x00, 0x00, 0x00, 0x00}, /* 24MHz XTal */
  2005. {0x14, 0x80, 0x00, 0x00, 0x00} /* 41MHz XTal */
  2006. };
  2007. static const uint8_t nominalRate6bw[3][5] = {
  2008. /* TRCG Nominal Rate [37:0] */
  2009. {0x17, 0xEA, 0xAA, 0xAA, 0xAA}, /* 20.5MHz XTal */
  2010. {0x1C, 0x00, 0x00, 0x00, 0x00}, /* 24MHz XTal */
  2011. {0x17, 0xEA, 0xAA, 0xAA, 0xAA} /* 41MHz XTal */
  2012. };
  2013. static const uint8_t nominalRate5bw[3][5] = {
  2014. /* TRCG Nominal Rate [37:0] */
  2015. {0x1C, 0xB3, 0x33, 0x33, 0x33}, /* 20.5MHz XTal */
  2016. {0x21, 0x99, 0x99, 0x99, 0x99}, /* 24MHz XTal */
  2017. {0x1C, 0xB3, 0x33, 0x33, 0x33} /* 41MHz XTal */
  2018. };
  2019. static const uint8_t nominalRate17bw[3][5] = {
  2020. /* TRCG Nominal Rate [37:0] */
  2021. {0x58, 0xE2, 0xAF, 0xE0, 0xBC}, /* 20.5MHz XTal */
  2022. {0x68, 0x0F, 0xA2, 0x32, 0xD0}, /* 24MHz XTal */
  2023. {0x58, 0xE2, 0xAF, 0xE0, 0xBC} /* 41MHz XTal */
  2024. };
  2025. static const uint8_t itbCoef8bw[3][14] = {
  2026. {0x26, 0xAF, 0x06, 0xCD, 0x13, 0xBB, 0x28, 0xBA,
  2027. 0x23, 0xA9, 0x1F, 0xA8, 0x2C, 0xC8}, /* 20.5MHz XTal */
  2028. {0x2F, 0xBA, 0x28, 0x9B, 0x28, 0x9D, 0x28, 0xA1,
  2029. 0x29, 0xA5, 0x2A, 0xAC, 0x29, 0xB5}, /* 24MHz XTal */
  2030. {0x26, 0xAF, 0x06, 0xCD, 0x13, 0xBB, 0x28, 0xBA,
  2031. 0x23, 0xA9, 0x1F, 0xA8, 0x2C, 0xC8} /* 41MHz XTal */
  2032. };
  2033. static const uint8_t itbCoef7bw[3][14] = {
  2034. {0x2C, 0xBD, 0x02, 0xCF, 0x04, 0xF8, 0x23, 0xA6,
  2035. 0x29, 0xB0, 0x26, 0xA9, 0x21, 0xA5}, /* 20.5MHz XTal */
  2036. {0x30, 0xB1, 0x29, 0x9A, 0x28, 0x9C, 0x28, 0xA0,
  2037. 0x29, 0xA2, 0x2B, 0xA6, 0x2B, 0xAD}, /* 24MHz XTal */
  2038. {0x2C, 0xBD, 0x02, 0xCF, 0x04, 0xF8, 0x23, 0xA6,
  2039. 0x29, 0xB0, 0x26, 0xA9, 0x21, 0xA5} /* 41MHz XTal */
  2040. };
  2041. static const uint8_t itbCoef6bw[3][14] = {
  2042. {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8,
  2043. 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4}, /* 20.5MHz XTal */
  2044. {0x31, 0xA8, 0x29, 0x9B, 0x27, 0x9C, 0x28, 0x9E,
  2045. 0x29, 0xA4, 0x29, 0xA2, 0x29, 0xA8}, /* 24MHz XTal */
  2046. {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8,
  2047. 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4} /* 41MHz XTal */
  2048. };
  2049. static const uint8_t itbCoef5bw[3][14] = {
  2050. {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8,
  2051. 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4}, /* 20.5MHz XTal */
  2052. {0x31, 0xA8, 0x29, 0x9B, 0x27, 0x9C, 0x28, 0x9E,
  2053. 0x29, 0xA4, 0x29, 0xA2, 0x29, 0xA8}, /* 24MHz XTal */
  2054. {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8,
  2055. 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4} /* 41MHz XTal */
  2056. };
  2057. static const uint8_t itbCoef17bw[3][14] = {
  2058. {0x25, 0xA0, 0x36, 0x8D, 0x2E, 0x94, 0x28, 0x9B,
  2059. 0x32, 0x90, 0x2C, 0x9D, 0x29, 0x99}, /* 20.5MHz XTal */
  2060. {0x33, 0x8E, 0x2B, 0x97, 0x2D, 0x95, 0x37, 0x8B,
  2061. 0x30, 0x97, 0x2D, 0x9A, 0x21, 0xA4}, /* 24MHz XTal */
  2062. {0x25, 0xA0, 0x36, 0x8D, 0x2E, 0x94, 0x28, 0x9B,
  2063. 0x32, 0x90, 0x2C, 0x9D, 0x29, 0x99} /* 41MHz XTal */
  2064. };
  2065. /* Set SLV-T Bank : 0x20 */
  2066. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20);
  2067. switch (bandwidth) {
  2068. case 8000000:
  2069. /* <Timing Recovery setting> */
  2070. cxd2841er_write_regs(priv, I2C_SLVT,
  2071. 0x9F, nominalRate8bw[priv->xtal], 5);
  2072. /* Set SLV-T Bank : 0x27 */
  2073. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x27);
  2074. cxd2841er_set_reg_bits(priv, I2C_SLVT,
  2075. 0x7a, 0x00, 0x0f);
  2076. /* Set SLV-T Bank : 0x10 */
  2077. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  2078. /* Group delay equaliser settings for
  2079. * ASCOT2D, ASCOT2E and ASCOT3 tuners
  2080. */
  2081. if (priv->flags & CXD2841ER_ASCOT)
  2082. cxd2841er_write_regs(priv, I2C_SLVT,
  2083. 0xA6, itbCoef8bw[priv->xtal], 14);
  2084. /* <IF freq setting> */
  2085. ifhz = cxd2841er_get_if_hz(priv, 4800000);
  2086. iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
  2087. data[0] = (u8) ((iffreq >> 16) & 0xff);
  2088. data[1] = (u8)((iffreq >> 8) & 0xff);
  2089. data[2] = (u8)(iffreq & 0xff);
  2090. cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
  2091. /* System bandwidth setting */
  2092. cxd2841er_set_reg_bits(
  2093. priv, I2C_SLVT, 0xD7, 0x00, 0x07);
  2094. break;
  2095. case 7000000:
  2096. /* <Timing Recovery setting> */
  2097. cxd2841er_write_regs(priv, I2C_SLVT,
  2098. 0x9F, nominalRate7bw[priv->xtal], 5);
  2099. /* Set SLV-T Bank : 0x27 */
  2100. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x27);
  2101. cxd2841er_set_reg_bits(priv, I2C_SLVT,
  2102. 0x7a, 0x00, 0x0f);
  2103. /* Set SLV-T Bank : 0x10 */
  2104. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  2105. /* Group delay equaliser settings for
  2106. * ASCOT2D, ASCOT2E and ASCOT3 tuners
  2107. */
  2108. if (priv->flags & CXD2841ER_ASCOT)
  2109. cxd2841er_write_regs(priv, I2C_SLVT,
  2110. 0xA6, itbCoef7bw[priv->xtal], 14);
  2111. /* <IF freq setting> */
  2112. ifhz = cxd2841er_get_if_hz(priv, 4200000);
  2113. iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
  2114. data[0] = (u8) ((iffreq >> 16) & 0xff);
  2115. data[1] = (u8)((iffreq >> 8) & 0xff);
  2116. data[2] = (u8)(iffreq & 0xff);
  2117. cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
  2118. /* System bandwidth setting */
  2119. cxd2841er_set_reg_bits(
  2120. priv, I2C_SLVT, 0xD7, 0x02, 0x07);
  2121. break;
  2122. case 6000000:
  2123. /* <Timing Recovery setting> */
  2124. cxd2841er_write_regs(priv, I2C_SLVT,
  2125. 0x9F, nominalRate6bw[priv->xtal], 5);
  2126. /* Set SLV-T Bank : 0x27 */
  2127. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x27);
  2128. cxd2841er_set_reg_bits(priv, I2C_SLVT,
  2129. 0x7a, 0x00, 0x0f);
  2130. /* Set SLV-T Bank : 0x10 */
  2131. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  2132. /* Group delay equaliser settings for
  2133. * ASCOT2D, ASCOT2E and ASCOT3 tuners
  2134. */
  2135. if (priv->flags & CXD2841ER_ASCOT)
  2136. cxd2841er_write_regs(priv, I2C_SLVT,
  2137. 0xA6, itbCoef6bw[priv->xtal], 14);
  2138. /* <IF freq setting> */
  2139. ifhz = cxd2841er_get_if_hz(priv, 3600000);
  2140. iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
  2141. data[0] = (u8) ((iffreq >> 16) & 0xff);
  2142. data[1] = (u8)((iffreq >> 8) & 0xff);
  2143. data[2] = (u8)(iffreq & 0xff);
  2144. cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
  2145. /* System bandwidth setting */
  2146. cxd2841er_set_reg_bits(
  2147. priv, I2C_SLVT, 0xD7, 0x04, 0x07);
  2148. break;
  2149. case 5000000:
  2150. /* <Timing Recovery setting> */
  2151. cxd2841er_write_regs(priv, I2C_SLVT,
  2152. 0x9F, nominalRate5bw[priv->xtal], 5);
  2153. /* Set SLV-T Bank : 0x27 */
  2154. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x27);
  2155. cxd2841er_set_reg_bits(priv, I2C_SLVT,
  2156. 0x7a, 0x00, 0x0f);
  2157. /* Set SLV-T Bank : 0x10 */
  2158. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  2159. /* Group delay equaliser settings for
  2160. * ASCOT2D, ASCOT2E and ASCOT3 tuners
  2161. */
  2162. if (priv->flags & CXD2841ER_ASCOT)
  2163. cxd2841er_write_regs(priv, I2C_SLVT,
  2164. 0xA6, itbCoef5bw[priv->xtal], 14);
  2165. /* <IF freq setting> */
  2166. ifhz = cxd2841er_get_if_hz(priv, 3600000);
  2167. iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
  2168. data[0] = (u8) ((iffreq >> 16) & 0xff);
  2169. data[1] = (u8)((iffreq >> 8) & 0xff);
  2170. data[2] = (u8)(iffreq & 0xff);
  2171. cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
  2172. /* System bandwidth setting */
  2173. cxd2841er_set_reg_bits(
  2174. priv, I2C_SLVT, 0xD7, 0x06, 0x07);
  2175. break;
  2176. case 1712000:
  2177. /* <Timing Recovery setting> */
  2178. cxd2841er_write_regs(priv, I2C_SLVT,
  2179. 0x9F, nominalRate17bw[priv->xtal], 5);
  2180. /* Set SLV-T Bank : 0x27 */
  2181. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x27);
  2182. cxd2841er_set_reg_bits(priv, I2C_SLVT,
  2183. 0x7a, 0x03, 0x0f);
  2184. /* Set SLV-T Bank : 0x10 */
  2185. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  2186. /* Group delay equaliser settings for
  2187. * ASCOT2D, ASCOT2E and ASCOT3 tuners
  2188. */
  2189. if (priv->flags & CXD2841ER_ASCOT)
  2190. cxd2841er_write_regs(priv, I2C_SLVT,
  2191. 0xA6, itbCoef17bw[priv->xtal], 14);
  2192. /* <IF freq setting> */
  2193. ifhz = cxd2841er_get_if_hz(priv, 3500000);
  2194. iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
  2195. data[0] = (u8) ((iffreq >> 16) & 0xff);
  2196. data[1] = (u8)((iffreq >> 8) & 0xff);
  2197. data[2] = (u8)(iffreq & 0xff);
  2198. cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
  2199. /* System bandwidth setting */
  2200. cxd2841er_set_reg_bits(
  2201. priv, I2C_SLVT, 0xD7, 0x03, 0x07);
  2202. break;
  2203. default:
  2204. return -EINVAL;
  2205. }
  2206. return 0;
  2207. }
  2208. static int cxd2841er_sleep_tc_to_active_t_band(
  2209. struct cxd2841er_priv *priv, u32 bandwidth)
  2210. {
  2211. u8 data[MAX_WRITE_REGSIZE];
  2212. u32 iffreq, ifhz;
  2213. static const u8 nominalRate8bw[3][5] = {
  2214. /* TRCG Nominal Rate [37:0] */
  2215. {0x11, 0xF0, 0x00, 0x00, 0x00}, /* 20.5MHz XTal */
  2216. {0x15, 0x00, 0x00, 0x00, 0x00}, /* 24MHz XTal */
  2217. {0x11, 0xF0, 0x00, 0x00, 0x00} /* 41MHz XTal */
  2218. };
  2219. static const u8 nominalRate7bw[3][5] = {
  2220. /* TRCG Nominal Rate [37:0] */
  2221. {0x14, 0x80, 0x00, 0x00, 0x00}, /* 20.5MHz XTal */
  2222. {0x18, 0x00, 0x00, 0x00, 0x00}, /* 24MHz XTal */
  2223. {0x14, 0x80, 0x00, 0x00, 0x00} /* 41MHz XTal */
  2224. };
  2225. static const u8 nominalRate6bw[3][5] = {
  2226. /* TRCG Nominal Rate [37:0] */
  2227. {0x17, 0xEA, 0xAA, 0xAA, 0xAA}, /* 20.5MHz XTal */
  2228. {0x1C, 0x00, 0x00, 0x00, 0x00}, /* 24MHz XTal */
  2229. {0x17, 0xEA, 0xAA, 0xAA, 0xAA} /* 41MHz XTal */
  2230. };
  2231. static const u8 nominalRate5bw[3][5] = {
  2232. /* TRCG Nominal Rate [37:0] */
  2233. {0x1C, 0xB3, 0x33, 0x33, 0x33}, /* 20.5MHz XTal */
  2234. {0x21, 0x99, 0x99, 0x99, 0x99}, /* 24MHz XTal */
  2235. {0x1C, 0xB3, 0x33, 0x33, 0x33} /* 41MHz XTal */
  2236. };
  2237. static const u8 itbCoef8bw[3][14] = {
  2238. {0x26, 0xAF, 0x06, 0xCD, 0x13, 0xBB, 0x28, 0xBA, 0x23, 0xA9,
  2239. 0x1F, 0xA8, 0x2C, 0xC8}, /* 20.5MHz XTal */
  2240. {0x2F, 0xBA, 0x28, 0x9B, 0x28, 0x9D, 0x28, 0xA1, 0x29, 0xA5,
  2241. 0x2A, 0xAC, 0x29, 0xB5}, /* 24MHz XTal */
  2242. {0x26, 0xAF, 0x06, 0xCD, 0x13, 0xBB, 0x28, 0xBA, 0x23, 0xA9,
  2243. 0x1F, 0xA8, 0x2C, 0xC8} /* 41MHz XTal */
  2244. };
  2245. static const u8 itbCoef7bw[3][14] = {
  2246. {0x2C, 0xBD, 0x02, 0xCF, 0x04, 0xF8, 0x23, 0xA6, 0x29, 0xB0,
  2247. 0x26, 0xA9, 0x21, 0xA5}, /* 20.5MHz XTal */
  2248. {0x30, 0xB1, 0x29, 0x9A, 0x28, 0x9C, 0x28, 0xA0, 0x29, 0xA2,
  2249. 0x2B, 0xA6, 0x2B, 0xAD}, /* 24MHz XTal */
  2250. {0x2C, 0xBD, 0x02, 0xCF, 0x04, 0xF8, 0x23, 0xA6, 0x29, 0xB0,
  2251. 0x26, 0xA9, 0x21, 0xA5} /* 41MHz XTal */
  2252. };
  2253. static const u8 itbCoef6bw[3][14] = {
  2254. {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, 0x00, 0xCF,
  2255. 0x00, 0xE6, 0x23, 0xA4}, /* 20.5MHz XTal */
  2256. {0x31, 0xA8, 0x29, 0x9B, 0x27, 0x9C, 0x28, 0x9E, 0x29, 0xA4,
  2257. 0x29, 0xA2, 0x29, 0xA8}, /* 24MHz XTal */
  2258. {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, 0x00, 0xCF,
  2259. 0x00, 0xE6, 0x23, 0xA4} /* 41MHz XTal */
  2260. };
  2261. static const u8 itbCoef5bw[3][14] = {
  2262. {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, 0x00, 0xCF,
  2263. 0x00, 0xE6, 0x23, 0xA4}, /* 20.5MHz XTal */
  2264. {0x31, 0xA8, 0x29, 0x9B, 0x27, 0x9C, 0x28, 0x9E, 0x29, 0xA4,
  2265. 0x29, 0xA2, 0x29, 0xA8}, /* 24MHz XTal */
  2266. {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, 0x00, 0xCF,
  2267. 0x00, 0xE6, 0x23, 0xA4} /* 41MHz XTal */
  2268. };
  2269. /* Set SLV-T Bank : 0x13 */
  2270. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x13);
  2271. /* Echo performance optimization setting */
  2272. data[0] = 0x01;
  2273. data[1] = 0x14;
  2274. cxd2841er_write_regs(priv, I2C_SLVT, 0x9C, data, 2);
  2275. /* Set SLV-T Bank : 0x10 */
  2276. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  2277. switch (bandwidth) {
  2278. case 8000000:
  2279. /* <Timing Recovery setting> */
  2280. cxd2841er_write_regs(priv, I2C_SLVT,
  2281. 0x9F, nominalRate8bw[priv->xtal], 5);
  2282. /* Group delay equaliser settings for
  2283. * ASCOT2D, ASCOT2E and ASCOT3 tuners
  2284. */
  2285. if (priv->flags & CXD2841ER_ASCOT)
  2286. cxd2841er_write_regs(priv, I2C_SLVT,
  2287. 0xA6, itbCoef8bw[priv->xtal], 14);
  2288. /* <IF freq setting> */
  2289. ifhz = cxd2841er_get_if_hz(priv, 4800000);
  2290. iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
  2291. data[0] = (u8) ((iffreq >> 16) & 0xff);
  2292. data[1] = (u8)((iffreq >> 8) & 0xff);
  2293. data[2] = (u8)(iffreq & 0xff);
  2294. cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
  2295. /* System bandwidth setting */
  2296. cxd2841er_set_reg_bits(
  2297. priv, I2C_SLVT, 0xD7, 0x00, 0x07);
  2298. /* Demod core latency setting */
  2299. if (priv->xtal == SONY_XTAL_24000) {
  2300. data[0] = 0x15;
  2301. data[1] = 0x28;
  2302. } else {
  2303. data[0] = 0x01;
  2304. data[1] = 0xE0;
  2305. }
  2306. cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2);
  2307. /* Notch filter setting */
  2308. data[0] = 0x01;
  2309. data[1] = 0x02;
  2310. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x17);
  2311. cxd2841er_write_regs(priv, I2C_SLVT, 0x38, data, 2);
  2312. break;
  2313. case 7000000:
  2314. /* <Timing Recovery setting> */
  2315. cxd2841er_write_regs(priv, I2C_SLVT,
  2316. 0x9F, nominalRate7bw[priv->xtal], 5);
  2317. /* Group delay equaliser settings for
  2318. * ASCOT2D, ASCOT2E and ASCOT3 tuners
  2319. */
  2320. if (priv->flags & CXD2841ER_ASCOT)
  2321. cxd2841er_write_regs(priv, I2C_SLVT,
  2322. 0xA6, itbCoef7bw[priv->xtal], 14);
  2323. /* <IF freq setting> */
  2324. ifhz = cxd2841er_get_if_hz(priv, 4200000);
  2325. iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
  2326. data[0] = (u8) ((iffreq >> 16) & 0xff);
  2327. data[1] = (u8)((iffreq >> 8) & 0xff);
  2328. data[2] = (u8)(iffreq & 0xff);
  2329. cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
  2330. /* System bandwidth setting */
  2331. cxd2841er_set_reg_bits(
  2332. priv, I2C_SLVT, 0xD7, 0x02, 0x07);
  2333. /* Demod core latency setting */
  2334. if (priv->xtal == SONY_XTAL_24000) {
  2335. data[0] = 0x1F;
  2336. data[1] = 0xF8;
  2337. } else {
  2338. data[0] = 0x12;
  2339. data[1] = 0xF8;
  2340. }
  2341. cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2);
  2342. /* Notch filter setting */
  2343. data[0] = 0x00;
  2344. data[1] = 0x03;
  2345. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x17);
  2346. cxd2841er_write_regs(priv, I2C_SLVT, 0x38, data, 2);
  2347. break;
  2348. case 6000000:
  2349. /* <Timing Recovery setting> */
  2350. cxd2841er_write_regs(priv, I2C_SLVT,
  2351. 0x9F, nominalRate6bw[priv->xtal], 5);
  2352. /* Group delay equaliser settings for
  2353. * ASCOT2D, ASCOT2E and ASCOT3 tuners
  2354. */
  2355. if (priv->flags & CXD2841ER_ASCOT)
  2356. cxd2841er_write_regs(priv, I2C_SLVT,
  2357. 0xA6, itbCoef6bw[priv->xtal], 14);
  2358. /* <IF freq setting> */
  2359. ifhz = cxd2841er_get_if_hz(priv, 3600000);
  2360. iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
  2361. data[0] = (u8) ((iffreq >> 16) & 0xff);
  2362. data[1] = (u8)((iffreq >> 8) & 0xff);
  2363. data[2] = (u8)(iffreq & 0xff);
  2364. cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
  2365. /* System bandwidth setting */
  2366. cxd2841er_set_reg_bits(
  2367. priv, I2C_SLVT, 0xD7, 0x04, 0x07);
  2368. /* Demod core latency setting */
  2369. if (priv->xtal == SONY_XTAL_24000) {
  2370. data[0] = 0x25;
  2371. data[1] = 0x4C;
  2372. } else {
  2373. data[0] = 0x1F;
  2374. data[1] = 0xDC;
  2375. }
  2376. cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2);
  2377. /* Notch filter setting */
  2378. data[0] = 0x00;
  2379. data[1] = 0x03;
  2380. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x17);
  2381. cxd2841er_write_regs(priv, I2C_SLVT, 0x38, data, 2);
  2382. break;
  2383. case 5000000:
  2384. /* <Timing Recovery setting> */
  2385. cxd2841er_write_regs(priv, I2C_SLVT,
  2386. 0x9F, nominalRate5bw[priv->xtal], 5);
  2387. /* Group delay equaliser settings for
  2388. * ASCOT2D, ASCOT2E and ASCOT3 tuners
  2389. */
  2390. if (priv->flags & CXD2841ER_ASCOT)
  2391. cxd2841er_write_regs(priv, I2C_SLVT,
  2392. 0xA6, itbCoef5bw[priv->xtal], 14);
  2393. /* <IF freq setting> */
  2394. ifhz = cxd2841er_get_if_hz(priv, 3600000);
  2395. iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
  2396. data[0] = (u8) ((iffreq >> 16) & 0xff);
  2397. data[1] = (u8)((iffreq >> 8) & 0xff);
  2398. data[2] = (u8)(iffreq & 0xff);
  2399. cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
  2400. /* System bandwidth setting */
  2401. cxd2841er_set_reg_bits(
  2402. priv, I2C_SLVT, 0xD7, 0x06, 0x07);
  2403. /* Demod core latency setting */
  2404. if (priv->xtal == SONY_XTAL_24000) {
  2405. data[0] = 0x2C;
  2406. data[1] = 0xC2;
  2407. } else {
  2408. data[0] = 0x26;
  2409. data[1] = 0x3C;
  2410. }
  2411. cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2);
  2412. /* Notch filter setting */
  2413. data[0] = 0x00;
  2414. data[1] = 0x03;
  2415. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x17);
  2416. cxd2841er_write_regs(priv, I2C_SLVT, 0x38, data, 2);
  2417. break;
  2418. }
  2419. return 0;
  2420. }
  2421. static int cxd2841er_sleep_tc_to_active_i_band(
  2422. struct cxd2841er_priv *priv, u32 bandwidth)
  2423. {
  2424. u32 iffreq, ifhz;
  2425. u8 data[3];
  2426. /* TRCG Nominal Rate */
  2427. static const u8 nominalRate8bw[3][5] = {
  2428. {0x00, 0x00, 0x00, 0x00, 0x00}, /* 20.5MHz XTal */
  2429. {0x11, 0xB8, 0x00, 0x00, 0x00}, /* 24MHz XTal */
  2430. {0x00, 0x00, 0x00, 0x00, 0x00} /* 41MHz XTal */
  2431. };
  2432. static const u8 nominalRate7bw[3][5] = {
  2433. {0x00, 0x00, 0x00, 0x00, 0x00}, /* 20.5MHz XTal */
  2434. {0x14, 0x40, 0x00, 0x00, 0x00}, /* 24MHz XTal */
  2435. {0x00, 0x00, 0x00, 0x00, 0x00} /* 41MHz XTal */
  2436. };
  2437. static const u8 nominalRate6bw[3][5] = {
  2438. {0x14, 0x2E, 0x00, 0x00, 0x00}, /* 20.5MHz XTal */
  2439. {0x17, 0xA0, 0x00, 0x00, 0x00}, /* 24MHz XTal */
  2440. {0x14, 0x2E, 0x00, 0x00, 0x00} /* 41MHz XTal */
  2441. };
  2442. static const u8 itbCoef8bw[3][14] = {
  2443. {0x00}, /* 20.5MHz XTal */
  2444. {0x2F, 0xBA, 0x28, 0x9B, 0x28, 0x9D, 0x28, 0xA1, 0x29,
  2445. 0xA5, 0x2A, 0xAC, 0x29, 0xB5}, /* 24MHz Xtal */
  2446. {0x0}, /* 41MHz XTal */
  2447. };
  2448. static const u8 itbCoef7bw[3][14] = {
  2449. {0x00}, /* 20.5MHz XTal */
  2450. {0x30, 0xB1, 0x29, 0x9A, 0x28, 0x9C, 0x28, 0xA0, 0x29,
  2451. 0xA2, 0x2B, 0xA6, 0x2B, 0xAD}, /* 24MHz Xtal */
  2452. {0x00}, /* 41MHz XTal */
  2453. };
  2454. static const u8 itbCoef6bw[3][14] = {
  2455. {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, 0x00,
  2456. 0xCF, 0x00, 0xE6, 0x23, 0xA4}, /* 20.5MHz XTal */
  2457. {0x31, 0xA8, 0x29, 0x9B, 0x27, 0x9C, 0x28, 0x9E, 0x29,
  2458. 0xA4, 0x29, 0xA2, 0x29, 0xA8}, /* 24MHz Xtal */
  2459. {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, 0x00,
  2460. 0xCF, 0x00, 0xE6, 0x23, 0xA4}, /* 41MHz XTal */
  2461. };
  2462. dev_dbg(&priv->i2c->dev, "%s() bandwidth=%u\n", __func__, bandwidth);
  2463. /* Set SLV-T Bank : 0x10 */
  2464. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  2465. /* 20.5/41MHz Xtal support is not available
  2466. * on ISDB-T 7MHzBW and 8MHzBW
  2467. */
  2468. if (priv->xtal != SONY_XTAL_24000 && bandwidth > 6000000) {
  2469. dev_err(&priv->i2c->dev,
  2470. "%s(): bandwidth %d supported only for 24MHz xtal\n",
  2471. __func__, bandwidth);
  2472. return -EINVAL;
  2473. }
  2474. switch (bandwidth) {
  2475. case 8000000:
  2476. /* TRCG Nominal Rate */
  2477. cxd2841er_write_regs(priv, I2C_SLVT,
  2478. 0x9F, nominalRate8bw[priv->xtal], 5);
  2479. /* Group delay equaliser settings for ASCOT tuners optimized */
  2480. if (priv->flags & CXD2841ER_ASCOT)
  2481. cxd2841er_write_regs(priv, I2C_SLVT,
  2482. 0xA6, itbCoef8bw[priv->xtal], 14);
  2483. /* IF freq setting */
  2484. ifhz = cxd2841er_get_if_hz(priv, 4750000);
  2485. iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
  2486. data[0] = (u8) ((iffreq >> 16) & 0xff);
  2487. data[1] = (u8)((iffreq >> 8) & 0xff);
  2488. data[2] = (u8)(iffreq & 0xff);
  2489. cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
  2490. /* System bandwidth setting */
  2491. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd7, 0x0, 0x7);
  2492. /* Demod core latency setting */
  2493. data[0] = 0x13;
  2494. data[1] = 0xFC;
  2495. cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2);
  2496. /* Acquisition optimization setting */
  2497. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x12);
  2498. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x71, 0x03, 0x07);
  2499. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x15);
  2500. cxd2841er_write_reg(priv, I2C_SLVT, 0xBE, 0x03);
  2501. break;
  2502. case 7000000:
  2503. /* TRCG Nominal Rate */
  2504. cxd2841er_write_regs(priv, I2C_SLVT,
  2505. 0x9F, nominalRate7bw[priv->xtal], 5);
  2506. /* Group delay equaliser settings for ASCOT tuners optimized */
  2507. if (priv->flags & CXD2841ER_ASCOT)
  2508. cxd2841er_write_regs(priv, I2C_SLVT,
  2509. 0xA6, itbCoef7bw[priv->xtal], 14);
  2510. /* IF freq setting */
  2511. ifhz = cxd2841er_get_if_hz(priv, 4150000);
  2512. iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
  2513. data[0] = (u8) ((iffreq >> 16) & 0xff);
  2514. data[1] = (u8)((iffreq >> 8) & 0xff);
  2515. data[2] = (u8)(iffreq & 0xff);
  2516. cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
  2517. /* System bandwidth setting */
  2518. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd7, 0x02, 0x7);
  2519. /* Demod core latency setting */
  2520. data[0] = 0x1A;
  2521. data[1] = 0xFA;
  2522. cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2);
  2523. /* Acquisition optimization setting */
  2524. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x12);
  2525. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x71, 0x03, 0x07);
  2526. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x15);
  2527. cxd2841er_write_reg(priv, I2C_SLVT, 0xBE, 0x02);
  2528. break;
  2529. case 6000000:
  2530. /* TRCG Nominal Rate */
  2531. cxd2841er_write_regs(priv, I2C_SLVT,
  2532. 0x9F, nominalRate6bw[priv->xtal], 5);
  2533. /* Group delay equaliser settings for ASCOT tuners optimized */
  2534. if (priv->flags & CXD2841ER_ASCOT)
  2535. cxd2841er_write_regs(priv, I2C_SLVT,
  2536. 0xA6, itbCoef6bw[priv->xtal], 14);
  2537. /* IF freq setting */
  2538. ifhz = cxd2841er_get_if_hz(priv, 3550000);
  2539. iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
  2540. data[0] = (u8) ((iffreq >> 16) & 0xff);
  2541. data[1] = (u8)((iffreq >> 8) & 0xff);
  2542. data[2] = (u8)(iffreq & 0xff);
  2543. cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
  2544. /* System bandwidth setting */
  2545. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd7, 0x04, 0x7);
  2546. /* Demod core latency setting */
  2547. if (priv->xtal == SONY_XTAL_24000) {
  2548. data[0] = 0x1F;
  2549. data[1] = 0x79;
  2550. } else {
  2551. data[0] = 0x1A;
  2552. data[1] = 0xE2;
  2553. }
  2554. cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2);
  2555. /* Acquisition optimization setting */
  2556. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x12);
  2557. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x71, 0x07, 0x07);
  2558. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x15);
  2559. cxd2841er_write_reg(priv, I2C_SLVT, 0xBE, 0x02);
  2560. break;
  2561. default:
  2562. dev_dbg(&priv->i2c->dev, "%s(): invalid bandwidth %d\n",
  2563. __func__, bandwidth);
  2564. return -EINVAL;
  2565. }
  2566. return 0;
  2567. }
  2568. static int cxd2841er_sleep_tc_to_active_c_band(struct cxd2841er_priv *priv,
  2569. u32 bandwidth)
  2570. {
  2571. u8 bw7_8mhz_b10_a6[] = {
  2572. 0x2D, 0xC7, 0x04, 0xF4, 0x07, 0xC5, 0x2A, 0xB8,
  2573. 0x27, 0x9E, 0x27, 0xA4, 0x29, 0xAB };
  2574. u8 bw6mhz_b10_a6[] = {
  2575. 0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8,
  2576. 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4 };
  2577. u8 b10_b6[3];
  2578. u32 iffreq, ifhz;
  2579. if (bandwidth != 6000000 &&
  2580. bandwidth != 7000000 &&
  2581. bandwidth != 8000000) {
  2582. dev_info(&priv->i2c->dev, "%s(): unsupported bandwidth %d. Forcing 8Mhz!\n",
  2583. __func__, bandwidth);
  2584. bandwidth = 8000000;
  2585. }
  2586. dev_dbg(&priv->i2c->dev, "%s() bw=%d\n", __func__, bandwidth);
  2587. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  2588. switch (bandwidth) {
  2589. case 8000000:
  2590. case 7000000:
  2591. if (priv->flags & CXD2841ER_ASCOT)
  2592. cxd2841er_write_regs(
  2593. priv, I2C_SLVT, 0xa6,
  2594. bw7_8mhz_b10_a6, sizeof(bw7_8mhz_b10_a6));
  2595. ifhz = cxd2841er_get_if_hz(priv, 4900000);
  2596. iffreq = cxd2841er_calc_iffreq(ifhz);
  2597. break;
  2598. case 6000000:
  2599. if (priv->flags & CXD2841ER_ASCOT)
  2600. cxd2841er_write_regs(
  2601. priv, I2C_SLVT, 0xa6,
  2602. bw6mhz_b10_a6, sizeof(bw6mhz_b10_a6));
  2603. ifhz = cxd2841er_get_if_hz(priv, 3700000);
  2604. iffreq = cxd2841er_calc_iffreq(ifhz);
  2605. break;
  2606. default:
  2607. dev_err(&priv->i2c->dev, "%s(): unsupported bandwidth %d\n",
  2608. __func__, bandwidth);
  2609. return -EINVAL;
  2610. }
  2611. /* <IF freq setting> */
  2612. b10_b6[0] = (u8) ((iffreq >> 16) & 0xff);
  2613. b10_b6[1] = (u8)((iffreq >> 8) & 0xff);
  2614. b10_b6[2] = (u8)(iffreq & 0xff);
  2615. cxd2841er_write_regs(priv, I2C_SLVT, 0xb6, b10_b6, sizeof(b10_b6));
  2616. /* Set SLV-T Bank : 0x11 */
  2617. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11);
  2618. switch (bandwidth) {
  2619. case 8000000:
  2620. case 7000000:
  2621. cxd2841er_set_reg_bits(
  2622. priv, I2C_SLVT, 0xa3, 0x00, 0x1f);
  2623. break;
  2624. case 6000000:
  2625. cxd2841er_set_reg_bits(
  2626. priv, I2C_SLVT, 0xa3, 0x14, 0x1f);
  2627. break;
  2628. }
  2629. /* Set SLV-T Bank : 0x40 */
  2630. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40);
  2631. switch (bandwidth) {
  2632. case 8000000:
  2633. cxd2841er_set_reg_bits(
  2634. priv, I2C_SLVT, 0x26, 0x0b, 0x0f);
  2635. cxd2841er_write_reg(priv, I2C_SLVT, 0x27, 0x3e);
  2636. break;
  2637. case 7000000:
  2638. cxd2841er_set_reg_bits(
  2639. priv, I2C_SLVT, 0x26, 0x09, 0x0f);
  2640. cxd2841er_write_reg(priv, I2C_SLVT, 0x27, 0xd6);
  2641. break;
  2642. case 6000000:
  2643. cxd2841er_set_reg_bits(
  2644. priv, I2C_SLVT, 0x26, 0x08, 0x0f);
  2645. cxd2841er_write_reg(priv, I2C_SLVT, 0x27, 0x6e);
  2646. break;
  2647. }
  2648. return 0;
  2649. }
  2650. static int cxd2841er_sleep_tc_to_active_t(struct cxd2841er_priv *priv,
  2651. u32 bandwidth)
  2652. {
  2653. u8 data[2] = { 0x09, 0x54 };
  2654. u8 data24m[3] = {0xDC, 0x6C, 0x00};
  2655. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  2656. cxd2841er_set_ts_clock_mode(priv, SYS_DVBT);
  2657. /* Set SLV-X Bank : 0x00 */
  2658. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  2659. /* Set demod mode */
  2660. cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x01);
  2661. /* Set SLV-T Bank : 0x00 */
  2662. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  2663. /* Enable demod clock */
  2664. cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01);
  2665. /* Disable RF level monitor */
  2666. cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00);
  2667. /* Enable ADC clock */
  2668. cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
  2669. /* Enable ADC 1 */
  2670. cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x1a);
  2671. /* Enable ADC 2 & 3 */
  2672. if (priv->xtal == SONY_XTAL_41000) {
  2673. data[0] = 0x0A;
  2674. data[1] = 0xD4;
  2675. }
  2676. cxd2841er_write_regs(priv, I2C_SLVT, 0x43, data, 2);
  2677. /* Enable ADC 4 */
  2678. cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00);
  2679. /* Set SLV-T Bank : 0x10 */
  2680. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  2681. /* IFAGC gain settings */
  2682. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd2, 0x0c, 0x1f);
  2683. /* Set SLV-T Bank : 0x11 */
  2684. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11);
  2685. /* BBAGC TARGET level setting */
  2686. cxd2841er_write_reg(priv, I2C_SLVT, 0x6a, 0x50);
  2687. /* Set SLV-T Bank : 0x10 */
  2688. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  2689. /* ASCOT setting */
  2690. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa5,
  2691. ((priv->flags & CXD2841ER_ASCOT) ? 0x01 : 0x00), 0x01);
  2692. /* Set SLV-T Bank : 0x18 */
  2693. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x18);
  2694. /* Pre-RS BER monitor setting */
  2695. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x36, 0x40, 0x07);
  2696. /* FEC Auto Recovery setting */
  2697. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x30, 0x01, 0x01);
  2698. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x31, 0x01, 0x01);
  2699. /* Set SLV-T Bank : 0x00 */
  2700. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  2701. /* TSIF setting */
  2702. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xce, 0x01, 0x01);
  2703. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcf, 0x01, 0x01);
  2704. if (priv->xtal == SONY_XTAL_24000) {
  2705. /* Set SLV-T Bank : 0x10 */
  2706. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  2707. cxd2841er_write_reg(priv, I2C_SLVT, 0xBF, 0x60);
  2708. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x18);
  2709. cxd2841er_write_regs(priv, I2C_SLVT, 0x24, data24m, 3);
  2710. }
  2711. cxd2841er_sleep_tc_to_active_t_band(priv, bandwidth);
  2712. /* Set SLV-T Bank : 0x00 */
  2713. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  2714. /* Disable HiZ Setting 1 */
  2715. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x28);
  2716. /* Disable HiZ Setting 2 */
  2717. cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00);
  2718. priv->state = STATE_ACTIVE_TC;
  2719. return 0;
  2720. }
  2721. static int cxd2841er_sleep_tc_to_active_t2(struct cxd2841er_priv *priv,
  2722. u32 bandwidth)
  2723. {
  2724. u8 data[MAX_WRITE_REGSIZE];
  2725. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  2726. cxd2841er_set_ts_clock_mode(priv, SYS_DVBT2);
  2727. /* Set SLV-X Bank : 0x00 */
  2728. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  2729. /* Set demod mode */
  2730. cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x02);
  2731. /* Set SLV-T Bank : 0x00 */
  2732. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  2733. /* Enable demod clock */
  2734. cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01);
  2735. /* Disable RF level monitor */
  2736. cxd2841er_write_reg(priv, I2C_SLVT, 0x59, 0x00);
  2737. cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00);
  2738. /* Enable ADC clock */
  2739. cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
  2740. /* Enable ADC 1 */
  2741. cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x1a);
  2742. if (priv->xtal == SONY_XTAL_41000) {
  2743. data[0] = 0x0A;
  2744. data[1] = 0xD4;
  2745. } else {
  2746. data[0] = 0x09;
  2747. data[1] = 0x54;
  2748. }
  2749. cxd2841er_write_regs(priv, I2C_SLVT, 0x43, data, 2);
  2750. /* Enable ADC 4 */
  2751. cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00);
  2752. /* Set SLV-T Bank : 0x10 */
  2753. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  2754. /* IFAGC gain settings */
  2755. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd2, 0x0c, 0x1f);
  2756. /* Set SLV-T Bank : 0x11 */
  2757. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11);
  2758. /* BBAGC TARGET level setting */
  2759. cxd2841er_write_reg(priv, I2C_SLVT, 0x6a, 0x50);
  2760. /* Set SLV-T Bank : 0x10 */
  2761. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  2762. /* ASCOT setting */
  2763. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa5,
  2764. ((priv->flags & CXD2841ER_ASCOT) ? 0x01 : 0x00), 0x01);
  2765. /* Set SLV-T Bank : 0x20 */
  2766. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20);
  2767. /* Acquisition optimization setting */
  2768. cxd2841er_write_reg(priv, I2C_SLVT, 0x8b, 0x3c);
  2769. /* Set SLV-T Bank : 0x2b */
  2770. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2b);
  2771. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x76, 0x20, 0x70);
  2772. /* Set SLV-T Bank : 0x23 */
  2773. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x23);
  2774. /* L1 Control setting */
  2775. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xE6, 0x00, 0x03);
  2776. /* Set SLV-T Bank : 0x00 */
  2777. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  2778. /* TSIF setting */
  2779. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xce, 0x01, 0x01);
  2780. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcf, 0x01, 0x01);
  2781. /* DVB-T2 initial setting */
  2782. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x13);
  2783. cxd2841er_write_reg(priv, I2C_SLVT, 0x83, 0x10);
  2784. cxd2841er_write_reg(priv, I2C_SLVT, 0x86, 0x34);
  2785. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x9e, 0x09, 0x0f);
  2786. cxd2841er_write_reg(priv, I2C_SLVT, 0x9f, 0xd8);
  2787. /* Set SLV-T Bank : 0x2a */
  2788. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2a);
  2789. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x38, 0x04, 0x0f);
  2790. /* Set SLV-T Bank : 0x2b */
  2791. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2b);
  2792. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x11, 0x20, 0x3f);
  2793. /* 24MHz Xtal setting */
  2794. if (priv->xtal == SONY_XTAL_24000) {
  2795. /* Set SLV-T Bank : 0x11 */
  2796. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11);
  2797. data[0] = 0xEB;
  2798. data[1] = 0x03;
  2799. data[2] = 0x3B;
  2800. cxd2841er_write_regs(priv, I2C_SLVT, 0x33, data, 3);
  2801. /* Set SLV-T Bank : 0x20 */
  2802. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20);
  2803. data[0] = 0x5E;
  2804. data[1] = 0x5E;
  2805. data[2] = 0x47;
  2806. cxd2841er_write_regs(priv, I2C_SLVT, 0x95, data, 3);
  2807. cxd2841er_write_reg(priv, I2C_SLVT, 0x99, 0x18);
  2808. data[0] = 0x3F;
  2809. data[1] = 0xFF;
  2810. cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2);
  2811. /* Set SLV-T Bank : 0x24 */
  2812. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x24);
  2813. data[0] = 0x0B;
  2814. data[1] = 0x72;
  2815. cxd2841er_write_regs(priv, I2C_SLVT, 0x34, data, 2);
  2816. data[0] = 0x93;
  2817. data[1] = 0xF3;
  2818. data[2] = 0x00;
  2819. cxd2841er_write_regs(priv, I2C_SLVT, 0xD2, data, 3);
  2820. data[0] = 0x05;
  2821. data[1] = 0xB8;
  2822. data[2] = 0xD8;
  2823. cxd2841er_write_regs(priv, I2C_SLVT, 0xDD, data, 3);
  2824. cxd2841er_write_reg(priv, I2C_SLVT, 0xE0, 0x00);
  2825. /* Set SLV-T Bank : 0x25 */
  2826. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x25);
  2827. cxd2841er_write_reg(priv, I2C_SLVT, 0xED, 0x60);
  2828. /* Set SLV-T Bank : 0x27 */
  2829. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x27);
  2830. cxd2841er_write_reg(priv, I2C_SLVT, 0xFA, 0x34);
  2831. /* Set SLV-T Bank : 0x2B */
  2832. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2B);
  2833. cxd2841er_write_reg(priv, I2C_SLVT, 0x4B, 0x2F);
  2834. cxd2841er_write_reg(priv, I2C_SLVT, 0x9E, 0x0E);
  2835. /* Set SLV-T Bank : 0x2D */
  2836. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2D);
  2837. data[0] = 0x89;
  2838. data[1] = 0x89;
  2839. cxd2841er_write_regs(priv, I2C_SLVT, 0x24, data, 2);
  2840. /* Set SLV-T Bank : 0x5E */
  2841. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x5E);
  2842. data[0] = 0x24;
  2843. data[1] = 0x95;
  2844. cxd2841er_write_regs(priv, I2C_SLVT, 0x8C, data, 2);
  2845. }
  2846. cxd2841er_sleep_tc_to_active_t2_band(priv, bandwidth);
  2847. /* Set SLV-T Bank : 0x00 */
  2848. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  2849. /* Disable HiZ Setting 1 */
  2850. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x28);
  2851. /* Disable HiZ Setting 2 */
  2852. cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00);
  2853. priv->state = STATE_ACTIVE_TC;
  2854. return 0;
  2855. }
  2856. /* ISDB-Tb part */
  2857. static int cxd2841er_sleep_tc_to_active_i(struct cxd2841er_priv *priv,
  2858. u32 bandwidth)
  2859. {
  2860. u8 data[2] = { 0x09, 0x54 };
  2861. u8 data24m[2] = {0x60, 0x00};
  2862. u8 data24m2[3] = {0xB7, 0x1B, 0x00};
  2863. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  2864. cxd2841er_set_ts_clock_mode(priv, SYS_DVBT);
  2865. /* Set SLV-X Bank : 0x00 */
  2866. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  2867. /* Set demod mode */
  2868. cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x06);
  2869. /* Set SLV-T Bank : 0x00 */
  2870. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  2871. /* Enable demod clock */
  2872. cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01);
  2873. /* Enable RF level monitor */
  2874. cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x01);
  2875. cxd2841er_write_reg(priv, I2C_SLVT, 0x59, 0x01);
  2876. /* Enable ADC clock */
  2877. cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
  2878. /* Enable ADC 1 */
  2879. cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x1a);
  2880. /* xtal freq 20.5MHz or 24M */
  2881. cxd2841er_write_regs(priv, I2C_SLVT, 0x43, data, 2);
  2882. /* Enable ADC 4 */
  2883. cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00);
  2884. /* ASCOT setting */
  2885. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa5,
  2886. ((priv->flags & CXD2841ER_ASCOT) ? 0x01 : 0x00), 0x01);
  2887. /* FEC Auto Recovery setting */
  2888. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x30, 0x01, 0x01);
  2889. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x31, 0x00, 0x01);
  2890. /* ISDB-T initial setting */
  2891. /* Set SLV-T Bank : 0x00 */
  2892. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  2893. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xce, 0x00, 0x01);
  2894. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcf, 0x00, 0x01);
  2895. /* Set SLV-T Bank : 0x10 */
  2896. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  2897. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x69, 0x04, 0x07);
  2898. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x6B, 0x03, 0x07);
  2899. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x9D, 0x50, 0xFF);
  2900. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xD3, 0x06, 0x1F);
  2901. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xED, 0x00, 0x01);
  2902. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xE2, 0xCE, 0x80);
  2903. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xF2, 0x13, 0x10);
  2904. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xDE, 0x2E, 0x3F);
  2905. /* Set SLV-T Bank : 0x15 */
  2906. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x15);
  2907. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xDE, 0x02, 0x03);
  2908. /* Set SLV-T Bank : 0x1E */
  2909. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x1E);
  2910. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x73, 0x68, 0xFF);
  2911. /* Set SLV-T Bank : 0x63 */
  2912. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x63);
  2913. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x81, 0x00, 0x01);
  2914. /* for xtal 24MHz */
  2915. /* Set SLV-T Bank : 0x10 */
  2916. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  2917. cxd2841er_write_regs(priv, I2C_SLVT, 0xBF, data24m, 2);
  2918. /* Set SLV-T Bank : 0x60 */
  2919. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x60);
  2920. cxd2841er_write_regs(priv, I2C_SLVT, 0xA8, data24m2, 3);
  2921. cxd2841er_sleep_tc_to_active_i_band(priv, bandwidth);
  2922. /* Set SLV-T Bank : 0x00 */
  2923. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  2924. /* Disable HiZ Setting 1 */
  2925. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x28);
  2926. /* Disable HiZ Setting 2 */
  2927. cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00);
  2928. priv->state = STATE_ACTIVE_TC;
  2929. return 0;
  2930. }
  2931. static int cxd2841er_sleep_tc_to_active_c(struct cxd2841er_priv *priv,
  2932. u32 bandwidth)
  2933. {
  2934. u8 data[2] = { 0x09, 0x54 };
  2935. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  2936. cxd2841er_set_ts_clock_mode(priv, SYS_DVBC_ANNEX_A);
  2937. /* Set SLV-X Bank : 0x00 */
  2938. cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
  2939. /* Set demod mode */
  2940. cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x04);
  2941. /* Set SLV-T Bank : 0x00 */
  2942. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  2943. /* Enable demod clock */
  2944. cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01);
  2945. /* Disable RF level monitor */
  2946. cxd2841er_write_reg(priv, I2C_SLVT, 0x59, 0x00);
  2947. cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00);
  2948. /* Enable ADC clock */
  2949. cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
  2950. /* Enable ADC 1 */
  2951. cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x1a);
  2952. /* xtal freq 20.5MHz */
  2953. cxd2841er_write_regs(priv, I2C_SLVT, 0x43, data, 2);
  2954. /* Enable ADC 4 */
  2955. cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00);
  2956. /* Set SLV-T Bank : 0x10 */
  2957. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  2958. /* IFAGC gain settings */
  2959. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd2, 0x09, 0x1f);
  2960. /* Set SLV-T Bank : 0x11 */
  2961. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11);
  2962. /* BBAGC TARGET level setting */
  2963. cxd2841er_write_reg(priv, I2C_SLVT, 0x6a, 0x48);
  2964. /* Set SLV-T Bank : 0x10 */
  2965. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  2966. /* ASCOT setting */
  2967. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa5,
  2968. ((priv->flags & CXD2841ER_ASCOT) ? 0x01 : 0x00), 0x01);
  2969. /* Set SLV-T Bank : 0x40 */
  2970. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40);
  2971. /* Demod setting */
  2972. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xc3, 0x00, 0x04);
  2973. /* Set SLV-T Bank : 0x00 */
  2974. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  2975. /* TSIF setting */
  2976. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xce, 0x01, 0x01);
  2977. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcf, 0x01, 0x01);
  2978. cxd2841er_sleep_tc_to_active_c_band(priv, bandwidth);
  2979. /* Set SLV-T Bank : 0x00 */
  2980. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  2981. /* Disable HiZ Setting 1 */
  2982. cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x28);
  2983. /* Disable HiZ Setting 2 */
  2984. cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00);
  2985. priv->state = STATE_ACTIVE_TC;
  2986. return 0;
  2987. }
  2988. static int cxd2841er_get_frontend(struct dvb_frontend *fe,
  2989. struct dtv_frontend_properties *p)
  2990. {
  2991. enum fe_status status = 0;
  2992. struct cxd2841er_priv *priv = fe->demodulator_priv;
  2993. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  2994. if (priv->state == STATE_ACTIVE_S)
  2995. cxd2841er_read_status_s(fe, &status);
  2996. else if (priv->state == STATE_ACTIVE_TC)
  2997. cxd2841er_read_status_tc(fe, &status);
  2998. if (priv->state == STATE_ACTIVE_TC || priv->state == STATE_ACTIVE_S)
  2999. cxd2841er_read_signal_strength(fe);
  3000. else
  3001. p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  3002. if (status & FE_HAS_LOCK) {
  3003. cxd2841er_read_snr(fe);
  3004. cxd2841er_read_ucblocks(fe);
  3005. cxd2841er_read_ber(fe);
  3006. } else {
  3007. p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  3008. p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  3009. p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  3010. p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  3011. }
  3012. return 0;
  3013. }
  3014. static int cxd2841er_set_frontend_s(struct dvb_frontend *fe)
  3015. {
  3016. int ret = 0, i, timeout, carr_offset;
  3017. enum fe_status status;
  3018. struct cxd2841er_priv *priv = fe->demodulator_priv;
  3019. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  3020. u32 symbol_rate = p->symbol_rate/1000;
  3021. dev_dbg(&priv->i2c->dev, "%s(): %s frequency=%d symbol_rate=%d xtal=%d\n",
  3022. __func__,
  3023. (p->delivery_system == SYS_DVBS ? "DVB-S" : "DVB-S2"),
  3024. p->frequency, symbol_rate, priv->xtal);
  3025. if (priv->flags & CXD2841ER_EARLY_TUNE)
  3026. cxd2841er_tuner_set(fe);
  3027. switch (priv->state) {
  3028. case STATE_SLEEP_S:
  3029. ret = cxd2841er_sleep_s_to_active_s(
  3030. priv, p->delivery_system, symbol_rate);
  3031. break;
  3032. case STATE_ACTIVE_S:
  3033. ret = cxd2841er_retune_active(priv, p);
  3034. break;
  3035. default:
  3036. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  3037. __func__, priv->state);
  3038. ret = -EINVAL;
  3039. goto done;
  3040. }
  3041. if (ret) {
  3042. dev_dbg(&priv->i2c->dev, "%s(): tune failed\n", __func__);
  3043. goto done;
  3044. }
  3045. if (!(priv->flags & CXD2841ER_EARLY_TUNE))
  3046. cxd2841er_tuner_set(fe);
  3047. cxd2841er_tune_done(priv);
  3048. timeout = ((3000000 + (symbol_rate - 1)) / symbol_rate) + 150;
  3049. i = 0;
  3050. do {
  3051. usleep_range(CXD2841ER_DVBS_POLLING_INVL*1000,
  3052. (CXD2841ER_DVBS_POLLING_INVL + 2) * 1000);
  3053. cxd2841er_read_status_s(fe, &status);
  3054. if (status & FE_HAS_LOCK)
  3055. break;
  3056. i++;
  3057. } while (i < timeout / CXD2841ER_DVBS_POLLING_INVL);
  3058. if (status & FE_HAS_LOCK) {
  3059. if (cxd2841er_get_carrier_offset_s_s2(
  3060. priv, &carr_offset)) {
  3061. ret = -EINVAL;
  3062. goto done;
  3063. }
  3064. dev_dbg(&priv->i2c->dev, "%s(): carrier_offset=%d\n",
  3065. __func__, carr_offset);
  3066. }
  3067. done:
  3068. /* Reset stats */
  3069. p->strength.stat[0].scale = FE_SCALE_RELATIVE;
  3070. p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  3071. p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  3072. p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  3073. p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  3074. return ret;
  3075. }
  3076. static int cxd2841er_set_frontend_tc(struct dvb_frontend *fe)
  3077. {
  3078. int ret = 0, timeout;
  3079. enum fe_status status;
  3080. struct cxd2841er_priv *priv = fe->demodulator_priv;
  3081. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  3082. dev_dbg(&priv->i2c->dev, "%s() delivery_system=%d bandwidth_hz=%d\n",
  3083. __func__, p->delivery_system, p->bandwidth_hz);
  3084. if (priv->flags & CXD2841ER_EARLY_TUNE)
  3085. cxd2841er_tuner_set(fe);
  3086. /* deconfigure/put demod to sleep on delsys switch if active */
  3087. if (priv->state == STATE_ACTIVE_TC &&
  3088. priv->system != p->delivery_system) {
  3089. dev_dbg(&priv->i2c->dev, "%s(): old_delsys=%d, new_delsys=%d -> sleep\n",
  3090. __func__, priv->system, p->delivery_system);
  3091. cxd2841er_sleep_tc(fe);
  3092. }
  3093. if (p->delivery_system == SYS_DVBT) {
  3094. priv->system = SYS_DVBT;
  3095. switch (priv->state) {
  3096. case STATE_SLEEP_TC:
  3097. ret = cxd2841er_sleep_tc_to_active_t(
  3098. priv, p->bandwidth_hz);
  3099. break;
  3100. case STATE_ACTIVE_TC:
  3101. ret = cxd2841er_retune_active(priv, p);
  3102. break;
  3103. default:
  3104. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  3105. __func__, priv->state);
  3106. ret = -EINVAL;
  3107. }
  3108. } else if (p->delivery_system == SYS_DVBT2) {
  3109. priv->system = SYS_DVBT2;
  3110. cxd2841er_dvbt2_set_plp_config(priv,
  3111. (int)(p->stream_id > 255), p->stream_id);
  3112. cxd2841er_dvbt2_set_profile(priv, DVBT2_PROFILE_BASE);
  3113. switch (priv->state) {
  3114. case STATE_SLEEP_TC:
  3115. ret = cxd2841er_sleep_tc_to_active_t2(priv,
  3116. p->bandwidth_hz);
  3117. break;
  3118. case STATE_ACTIVE_TC:
  3119. ret = cxd2841er_retune_active(priv, p);
  3120. break;
  3121. default:
  3122. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  3123. __func__, priv->state);
  3124. ret = -EINVAL;
  3125. }
  3126. } else if (p->delivery_system == SYS_ISDBT) {
  3127. priv->system = SYS_ISDBT;
  3128. switch (priv->state) {
  3129. case STATE_SLEEP_TC:
  3130. ret = cxd2841er_sleep_tc_to_active_i(
  3131. priv, p->bandwidth_hz);
  3132. break;
  3133. case STATE_ACTIVE_TC:
  3134. ret = cxd2841er_retune_active(priv, p);
  3135. break;
  3136. default:
  3137. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  3138. __func__, priv->state);
  3139. ret = -EINVAL;
  3140. }
  3141. } else if (p->delivery_system == SYS_DVBC_ANNEX_A ||
  3142. p->delivery_system == SYS_DVBC_ANNEX_C) {
  3143. priv->system = SYS_DVBC_ANNEX_A;
  3144. /* correct bandwidth */
  3145. if (p->bandwidth_hz != 6000000 &&
  3146. p->bandwidth_hz != 7000000 &&
  3147. p->bandwidth_hz != 8000000) {
  3148. p->bandwidth_hz = 8000000;
  3149. dev_dbg(&priv->i2c->dev, "%s(): forcing bandwidth to %d\n",
  3150. __func__, p->bandwidth_hz);
  3151. }
  3152. switch (priv->state) {
  3153. case STATE_SLEEP_TC:
  3154. ret = cxd2841er_sleep_tc_to_active_c(
  3155. priv, p->bandwidth_hz);
  3156. break;
  3157. case STATE_ACTIVE_TC:
  3158. ret = cxd2841er_retune_active(priv, p);
  3159. break;
  3160. default:
  3161. dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
  3162. __func__, priv->state);
  3163. ret = -EINVAL;
  3164. }
  3165. } else {
  3166. dev_dbg(&priv->i2c->dev,
  3167. "%s(): invalid delivery system %d\n",
  3168. __func__, p->delivery_system);
  3169. ret = -EINVAL;
  3170. }
  3171. if (ret)
  3172. goto done;
  3173. if (!(priv->flags & CXD2841ER_EARLY_TUNE))
  3174. cxd2841er_tuner_set(fe);
  3175. cxd2841er_tune_done(priv);
  3176. if (priv->flags & CXD2841ER_NO_WAIT_LOCK)
  3177. goto done;
  3178. timeout = 2500;
  3179. while (timeout > 0) {
  3180. ret = cxd2841er_read_status_tc(fe, &status);
  3181. if (ret)
  3182. goto done;
  3183. if (status & FE_HAS_LOCK)
  3184. break;
  3185. msleep(20);
  3186. timeout -= 20;
  3187. }
  3188. if (timeout < 0)
  3189. dev_dbg(&priv->i2c->dev,
  3190. "%s(): LOCK wait timeout\n", __func__);
  3191. done:
  3192. return ret;
  3193. }
  3194. static int cxd2841er_tune_s(struct dvb_frontend *fe,
  3195. bool re_tune,
  3196. unsigned int mode_flags,
  3197. unsigned int *delay,
  3198. enum fe_status *status)
  3199. {
  3200. int ret, carrier_offset;
  3201. struct cxd2841er_priv *priv = fe->demodulator_priv;
  3202. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  3203. dev_dbg(&priv->i2c->dev, "%s() re_tune=%d\n", __func__, re_tune);
  3204. if (re_tune) {
  3205. ret = cxd2841er_set_frontend_s(fe);
  3206. if (ret)
  3207. return ret;
  3208. cxd2841er_read_status_s(fe, status);
  3209. if (*status & FE_HAS_LOCK) {
  3210. if (cxd2841er_get_carrier_offset_s_s2(
  3211. priv, &carrier_offset))
  3212. return -EINVAL;
  3213. p->frequency += carrier_offset;
  3214. ret = cxd2841er_set_frontend_s(fe);
  3215. if (ret)
  3216. return ret;
  3217. }
  3218. }
  3219. *delay = HZ / 5;
  3220. return cxd2841er_read_status_s(fe, status);
  3221. }
  3222. static int cxd2841er_tune_tc(struct dvb_frontend *fe,
  3223. bool re_tune,
  3224. unsigned int mode_flags,
  3225. unsigned int *delay,
  3226. enum fe_status *status)
  3227. {
  3228. int ret, carrier_offset;
  3229. struct cxd2841er_priv *priv = fe->demodulator_priv;
  3230. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  3231. dev_dbg(&priv->i2c->dev, "%s(): re_tune %d bandwidth=%d\n", __func__,
  3232. re_tune, p->bandwidth_hz);
  3233. if (re_tune) {
  3234. ret = cxd2841er_set_frontend_tc(fe);
  3235. if (ret)
  3236. return ret;
  3237. cxd2841er_read_status_tc(fe, status);
  3238. if (*status & FE_HAS_LOCK) {
  3239. switch (priv->system) {
  3240. case SYS_ISDBT:
  3241. ret = cxd2841er_get_carrier_offset_i(
  3242. priv, p->bandwidth_hz,
  3243. &carrier_offset);
  3244. if (ret)
  3245. return ret;
  3246. break;
  3247. case SYS_DVBT:
  3248. ret = cxd2841er_get_carrier_offset_t(
  3249. priv, p->bandwidth_hz,
  3250. &carrier_offset);
  3251. if (ret)
  3252. return ret;
  3253. break;
  3254. case SYS_DVBT2:
  3255. ret = cxd2841er_get_carrier_offset_t2(
  3256. priv, p->bandwidth_hz,
  3257. &carrier_offset);
  3258. if (ret)
  3259. return ret;
  3260. break;
  3261. case SYS_DVBC_ANNEX_A:
  3262. ret = cxd2841er_get_carrier_offset_c(
  3263. priv, &carrier_offset);
  3264. if (ret)
  3265. return ret;
  3266. break;
  3267. default:
  3268. dev_dbg(&priv->i2c->dev,
  3269. "%s(): invalid delivery system %d\n",
  3270. __func__, priv->system);
  3271. return -EINVAL;
  3272. }
  3273. dev_dbg(&priv->i2c->dev, "%s(): carrier offset %d\n",
  3274. __func__, carrier_offset);
  3275. p->frequency += carrier_offset;
  3276. ret = cxd2841er_set_frontend_tc(fe);
  3277. if (ret)
  3278. return ret;
  3279. }
  3280. }
  3281. *delay = HZ / 5;
  3282. return cxd2841er_read_status_tc(fe, status);
  3283. }
  3284. static int cxd2841er_sleep_s(struct dvb_frontend *fe)
  3285. {
  3286. struct cxd2841er_priv *priv = fe->demodulator_priv;
  3287. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  3288. cxd2841er_active_s_to_sleep_s(fe->demodulator_priv);
  3289. cxd2841er_sleep_s_to_shutdown(fe->demodulator_priv);
  3290. return 0;
  3291. }
  3292. static int cxd2841er_sleep_tc(struct dvb_frontend *fe)
  3293. {
  3294. struct cxd2841er_priv *priv = fe->demodulator_priv;
  3295. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  3296. if (priv->state == STATE_ACTIVE_TC) {
  3297. switch (priv->system) {
  3298. case SYS_DVBT:
  3299. cxd2841er_active_t_to_sleep_tc(priv);
  3300. break;
  3301. case SYS_DVBT2:
  3302. cxd2841er_active_t2_to_sleep_tc(priv);
  3303. break;
  3304. case SYS_ISDBT:
  3305. cxd2841er_active_i_to_sleep_tc(priv);
  3306. break;
  3307. case SYS_DVBC_ANNEX_A:
  3308. cxd2841er_active_c_to_sleep_tc(priv);
  3309. break;
  3310. default:
  3311. dev_warn(&priv->i2c->dev,
  3312. "%s(): unknown delivery system %d\n",
  3313. __func__, priv->system);
  3314. }
  3315. }
  3316. if (priv->state != STATE_SLEEP_TC) {
  3317. dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
  3318. __func__, priv->state);
  3319. return -EINVAL;
  3320. }
  3321. return 0;
  3322. }
  3323. static int cxd2841er_shutdown_tc(struct dvb_frontend *fe)
  3324. {
  3325. struct cxd2841er_priv *priv = fe->demodulator_priv;
  3326. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  3327. if (!cxd2841er_sleep_tc(fe))
  3328. cxd2841er_sleep_tc_to_shutdown(priv);
  3329. return 0;
  3330. }
  3331. static int cxd2841er_send_burst(struct dvb_frontend *fe,
  3332. enum fe_sec_mini_cmd burst)
  3333. {
  3334. u8 data;
  3335. struct cxd2841er_priv *priv = fe->demodulator_priv;
  3336. dev_dbg(&priv->i2c->dev, "%s(): burst mode %s\n", __func__,
  3337. (burst == SEC_MINI_A ? "A" : "B"));
  3338. if (priv->state != STATE_SLEEP_S &&
  3339. priv->state != STATE_ACTIVE_S) {
  3340. dev_err(&priv->i2c->dev, "%s(): invalid demod state %d\n",
  3341. __func__, priv->state);
  3342. return -EINVAL;
  3343. }
  3344. data = (burst == SEC_MINI_A ? 0 : 1);
  3345. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xbb);
  3346. cxd2841er_write_reg(priv, I2C_SLVT, 0x34, 0x01);
  3347. cxd2841er_write_reg(priv, I2C_SLVT, 0x35, data);
  3348. return 0;
  3349. }
  3350. static int cxd2841er_set_tone(struct dvb_frontend *fe,
  3351. enum fe_sec_tone_mode tone)
  3352. {
  3353. u8 data;
  3354. struct cxd2841er_priv *priv = fe->demodulator_priv;
  3355. dev_dbg(&priv->i2c->dev, "%s(): tone %s\n", __func__,
  3356. (tone == SEC_TONE_ON ? "On" : "Off"));
  3357. if (priv->state != STATE_SLEEP_S &&
  3358. priv->state != STATE_ACTIVE_S) {
  3359. dev_err(&priv->i2c->dev, "%s(): invalid demod state %d\n",
  3360. __func__, priv->state);
  3361. return -EINVAL;
  3362. }
  3363. data = (tone == SEC_TONE_ON ? 1 : 0);
  3364. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xbb);
  3365. cxd2841er_write_reg(priv, I2C_SLVT, 0x36, data);
  3366. return 0;
  3367. }
  3368. static int cxd2841er_send_diseqc_msg(struct dvb_frontend *fe,
  3369. struct dvb_diseqc_master_cmd *cmd)
  3370. {
  3371. int i;
  3372. u8 data[12];
  3373. struct cxd2841er_priv *priv = fe->demodulator_priv;
  3374. if (priv->state != STATE_SLEEP_S &&
  3375. priv->state != STATE_ACTIVE_S) {
  3376. dev_err(&priv->i2c->dev, "%s(): invalid demod state %d\n",
  3377. __func__, priv->state);
  3378. return -EINVAL;
  3379. }
  3380. dev_dbg(&priv->i2c->dev,
  3381. "%s(): cmd->len %d\n", __func__, cmd->msg_len);
  3382. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xbb);
  3383. /* DiDEqC enable */
  3384. cxd2841er_write_reg(priv, I2C_SLVT, 0x33, 0x01);
  3385. /* cmd1 length & data */
  3386. cxd2841er_write_reg(priv, I2C_SLVT, 0x3d, cmd->msg_len);
  3387. memset(data, 0, sizeof(data));
  3388. for (i = 0; i < cmd->msg_len && i < sizeof(data); i++)
  3389. data[i] = cmd->msg[i];
  3390. cxd2841er_write_regs(priv, I2C_SLVT, 0x3e, data, sizeof(data));
  3391. /* repeat count for cmd1 */
  3392. cxd2841er_write_reg(priv, I2C_SLVT, 0x37, 1);
  3393. /* repeat count for cmd2: always 0 */
  3394. cxd2841er_write_reg(priv, I2C_SLVT, 0x38, 0);
  3395. /* start transmit */
  3396. cxd2841er_write_reg(priv, I2C_SLVT, 0x32, 0x01);
  3397. /* wait for 1 sec timeout */
  3398. for (i = 0; i < 50; i++) {
  3399. cxd2841er_read_reg(priv, I2C_SLVT, 0x10, data);
  3400. if (!data[0]) {
  3401. dev_dbg(&priv->i2c->dev,
  3402. "%s(): DiSEqC cmd has been sent\n", __func__);
  3403. return 0;
  3404. }
  3405. msleep(20);
  3406. }
  3407. dev_dbg(&priv->i2c->dev,
  3408. "%s(): DiSEqC cmd transmit timeout\n", __func__);
  3409. return -ETIMEDOUT;
  3410. }
  3411. static void cxd2841er_release(struct dvb_frontend *fe)
  3412. {
  3413. struct cxd2841er_priv *priv = fe->demodulator_priv;
  3414. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  3415. kfree(priv);
  3416. }
  3417. static int cxd2841er_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
  3418. {
  3419. struct cxd2841er_priv *priv = fe->demodulator_priv;
  3420. dev_dbg(&priv->i2c->dev, "%s(): enable=%d\n", __func__, enable);
  3421. cxd2841er_set_reg_bits(
  3422. priv, I2C_SLVX, 0x8, (enable ? 0x01 : 0x00), 0x01);
  3423. return 0;
  3424. }
  3425. static enum dvbfe_algo cxd2841er_get_algo(struct dvb_frontend *fe)
  3426. {
  3427. struct cxd2841er_priv *priv = fe->demodulator_priv;
  3428. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  3429. return DVBFE_ALGO_HW;
  3430. }
  3431. static void cxd2841er_init_stats(struct dvb_frontend *fe)
  3432. {
  3433. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  3434. p->strength.len = 1;
  3435. p->strength.stat[0].scale = FE_SCALE_RELATIVE;
  3436. p->cnr.len = 1;
  3437. p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  3438. p->block_error.len = 1;
  3439. p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  3440. p->post_bit_error.len = 1;
  3441. p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  3442. p->post_bit_count.len = 1;
  3443. p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  3444. }
  3445. static int cxd2841er_init_s(struct dvb_frontend *fe)
  3446. {
  3447. struct cxd2841er_priv *priv = fe->demodulator_priv;
  3448. /* sanity. force demod to SHUTDOWN state */
  3449. if (priv->state == STATE_SLEEP_S) {
  3450. dev_dbg(&priv->i2c->dev, "%s() forcing sleep->shutdown\n",
  3451. __func__);
  3452. cxd2841er_sleep_s_to_shutdown(priv);
  3453. } else if (priv->state == STATE_ACTIVE_S) {
  3454. dev_dbg(&priv->i2c->dev, "%s() forcing active->sleep->shutdown\n",
  3455. __func__);
  3456. cxd2841er_active_s_to_sleep_s(priv);
  3457. cxd2841er_sleep_s_to_shutdown(priv);
  3458. }
  3459. dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
  3460. cxd2841er_shutdown_to_sleep_s(priv);
  3461. /* SONY_DEMOD_CONFIG_SAT_IFAGCNEG set to 1 */
  3462. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0);
  3463. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xb9, 0x01, 0x01);
  3464. cxd2841er_init_stats(fe);
  3465. return 0;
  3466. }
  3467. static int cxd2841er_init_tc(struct dvb_frontend *fe)
  3468. {
  3469. struct cxd2841er_priv *priv = fe->demodulator_priv;
  3470. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  3471. dev_dbg(&priv->i2c->dev, "%s() bandwidth_hz=%d\n",
  3472. __func__, p->bandwidth_hz);
  3473. cxd2841er_shutdown_to_sleep_tc(priv);
  3474. /* SONY_DEMOD_CONFIG_IFAGCNEG = 1 (0 for NO_AGCNEG */
  3475. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
  3476. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcb,
  3477. ((priv->flags & CXD2841ER_NO_AGCNEG) ? 0x00 : 0x40), 0x40);
  3478. /* SONY_DEMOD_CONFIG_IFAGC_ADC_FS = 0 */
  3479. cxd2841er_write_reg(priv, I2C_SLVT, 0xcd, 0x50);
  3480. /* SONY_DEMOD_CONFIG_PARALLEL_SEL = 1 */
  3481. cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
  3482. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xc4,
  3483. ((priv->flags & CXD2841ER_TS_SERIAL) ? 0x80 : 0x00), 0x80);
  3484. /* clear TSCFG bits 3+4 */
  3485. if (priv->flags & CXD2841ER_TSBITS)
  3486. cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xc4, 0x00, 0x18);
  3487. cxd2841er_init_stats(fe);
  3488. return 0;
  3489. }
  3490. static const struct dvb_frontend_ops cxd2841er_dvbs_s2_ops;
  3491. static struct dvb_frontend_ops cxd2841er_t_c_ops;
  3492. static struct dvb_frontend *cxd2841er_attach(struct cxd2841er_config *cfg,
  3493. struct i2c_adapter *i2c,
  3494. u8 system)
  3495. {
  3496. u8 chip_id = 0;
  3497. const char *type;
  3498. const char *name;
  3499. struct cxd2841er_priv *priv = NULL;
  3500. /* allocate memory for the internal state */
  3501. priv = kzalloc(sizeof(struct cxd2841er_priv), GFP_KERNEL);
  3502. if (!priv)
  3503. return NULL;
  3504. priv->i2c = i2c;
  3505. priv->config = cfg;
  3506. priv->i2c_addr_slvx = (cfg->i2c_addr + 4) >> 1;
  3507. priv->i2c_addr_slvt = (cfg->i2c_addr) >> 1;
  3508. priv->xtal = cfg->xtal;
  3509. priv->flags = cfg->flags;
  3510. priv->frontend.demodulator_priv = priv;
  3511. dev_info(&priv->i2c->dev,
  3512. "%s(): I2C adapter %p SLVX addr %x SLVT addr %x\n",
  3513. __func__, priv->i2c,
  3514. priv->i2c_addr_slvx, priv->i2c_addr_slvt);
  3515. chip_id = cxd2841er_chip_id(priv);
  3516. switch (chip_id) {
  3517. case CXD2837ER_CHIP_ID:
  3518. snprintf(cxd2841er_t_c_ops.info.name, 128,
  3519. "Sony CXD2837ER DVB-T/T2/C demodulator");
  3520. name = "CXD2837ER";
  3521. type = "C/T/T2";
  3522. break;
  3523. case CXD2838ER_CHIP_ID:
  3524. snprintf(cxd2841er_t_c_ops.info.name, 128,
  3525. "Sony CXD2838ER ISDB-T demodulator");
  3526. cxd2841er_t_c_ops.delsys[0] = SYS_ISDBT;
  3527. cxd2841er_t_c_ops.delsys[1] = SYS_UNDEFINED;
  3528. cxd2841er_t_c_ops.delsys[2] = SYS_UNDEFINED;
  3529. name = "CXD2838ER";
  3530. type = "ISDB-T";
  3531. break;
  3532. case CXD2841ER_CHIP_ID:
  3533. snprintf(cxd2841er_t_c_ops.info.name, 128,
  3534. "Sony CXD2841ER DVB-T/T2/C demodulator");
  3535. name = "CXD2841ER";
  3536. type = "T/T2/C/ISDB-T";
  3537. break;
  3538. case CXD2843ER_CHIP_ID:
  3539. snprintf(cxd2841er_t_c_ops.info.name, 128,
  3540. "Sony CXD2843ER DVB-T/T2/C/C2 demodulator");
  3541. name = "CXD2843ER";
  3542. type = "C/C2/T/T2";
  3543. break;
  3544. case CXD2854ER_CHIP_ID:
  3545. snprintf(cxd2841er_t_c_ops.info.name, 128,
  3546. "Sony CXD2854ER DVB-T/T2/C and ISDB-T demodulator");
  3547. cxd2841er_t_c_ops.delsys[3] = SYS_ISDBT;
  3548. name = "CXD2854ER";
  3549. type = "C/C2/T/T2/ISDB-T";
  3550. break;
  3551. default:
  3552. dev_err(&priv->i2c->dev, "%s(): invalid chip ID 0x%02x\n",
  3553. __func__, chip_id);
  3554. priv->frontend.demodulator_priv = NULL;
  3555. kfree(priv);
  3556. return NULL;
  3557. }
  3558. /* create dvb_frontend */
  3559. if (system == SYS_DVBS) {
  3560. memcpy(&priv->frontend.ops,
  3561. &cxd2841er_dvbs_s2_ops,
  3562. sizeof(struct dvb_frontend_ops));
  3563. type = "S/S2";
  3564. } else {
  3565. memcpy(&priv->frontend.ops,
  3566. &cxd2841er_t_c_ops,
  3567. sizeof(struct dvb_frontend_ops));
  3568. }
  3569. dev_info(&priv->i2c->dev,
  3570. "%s(): attaching %s DVB-%s frontend\n",
  3571. __func__, name, type);
  3572. dev_info(&priv->i2c->dev, "%s(): chip ID 0x%02x OK.\n",
  3573. __func__, chip_id);
  3574. return &priv->frontend;
  3575. }
  3576. struct dvb_frontend *cxd2841er_attach_s(struct cxd2841er_config *cfg,
  3577. struct i2c_adapter *i2c)
  3578. {
  3579. return cxd2841er_attach(cfg, i2c, SYS_DVBS);
  3580. }
  3581. EXPORT_SYMBOL(cxd2841er_attach_s);
  3582. struct dvb_frontend *cxd2841er_attach_t_c(struct cxd2841er_config *cfg,
  3583. struct i2c_adapter *i2c)
  3584. {
  3585. return cxd2841er_attach(cfg, i2c, 0);
  3586. }
  3587. EXPORT_SYMBOL(cxd2841er_attach_t_c);
  3588. static const struct dvb_frontend_ops cxd2841er_dvbs_s2_ops = {
  3589. .delsys = { SYS_DVBS, SYS_DVBS2 },
  3590. .info = {
  3591. .name = "Sony CXD2841ER DVB-S/S2 demodulator",
  3592. .frequency_min_hz = 500 * MHz,
  3593. .frequency_max_hz = 2500 * MHz,
  3594. .symbol_rate_min = 1000000,
  3595. .symbol_rate_max = 45000000,
  3596. .symbol_rate_tolerance = 500,
  3597. .caps = FE_CAN_INVERSION_AUTO |
  3598. FE_CAN_FEC_AUTO |
  3599. FE_CAN_QPSK,
  3600. },
  3601. .init = cxd2841er_init_s,
  3602. .sleep = cxd2841er_sleep_s,
  3603. .release = cxd2841er_release,
  3604. .set_frontend = cxd2841er_set_frontend_s,
  3605. .get_frontend = cxd2841er_get_frontend,
  3606. .read_status = cxd2841er_read_status_s,
  3607. .i2c_gate_ctrl = cxd2841er_i2c_gate_ctrl,
  3608. .get_frontend_algo = cxd2841er_get_algo,
  3609. .set_tone = cxd2841er_set_tone,
  3610. .diseqc_send_burst = cxd2841er_send_burst,
  3611. .diseqc_send_master_cmd = cxd2841er_send_diseqc_msg,
  3612. .tune = cxd2841er_tune_s
  3613. };
  3614. static struct dvb_frontend_ops cxd2841er_t_c_ops = {
  3615. .delsys = { SYS_DVBT, SYS_DVBT2, SYS_DVBC_ANNEX_A },
  3616. .info = {
  3617. .name = "", /* will set in attach function */
  3618. .caps = FE_CAN_FEC_1_2 |
  3619. FE_CAN_FEC_2_3 |
  3620. FE_CAN_FEC_3_4 |
  3621. FE_CAN_FEC_5_6 |
  3622. FE_CAN_FEC_7_8 |
  3623. FE_CAN_FEC_AUTO |
  3624. FE_CAN_QPSK |
  3625. FE_CAN_QAM_16 |
  3626. FE_CAN_QAM_32 |
  3627. FE_CAN_QAM_64 |
  3628. FE_CAN_QAM_128 |
  3629. FE_CAN_QAM_256 |
  3630. FE_CAN_QAM_AUTO |
  3631. FE_CAN_TRANSMISSION_MODE_AUTO |
  3632. FE_CAN_GUARD_INTERVAL_AUTO |
  3633. FE_CAN_HIERARCHY_AUTO |
  3634. FE_CAN_MUTE_TS |
  3635. FE_CAN_2G_MODULATION,
  3636. .frequency_min_hz = 42 * MHz,
  3637. .frequency_max_hz = 1002 * MHz,
  3638. .symbol_rate_min = 870000,
  3639. .symbol_rate_max = 11700000
  3640. },
  3641. .init = cxd2841er_init_tc,
  3642. .sleep = cxd2841er_shutdown_tc,
  3643. .release = cxd2841er_release,
  3644. .set_frontend = cxd2841er_set_frontend_tc,
  3645. .get_frontend = cxd2841er_get_frontend,
  3646. .read_status = cxd2841er_read_status_tc,
  3647. .tune = cxd2841er_tune_tc,
  3648. .i2c_gate_ctrl = cxd2841er_i2c_gate_ctrl,
  3649. .get_frontend_algo = cxd2841er_get_algo
  3650. };
  3651. MODULE_DESCRIPTION("Sony CXD2837/38/41/43/54ER DVB-C/C2/T/T2/S/S2 demodulator driver");
  3652. MODULE_AUTHOR("Sergey Kozlov <serjk@netup.ru>, Abylay Ospan <aospan@netup.ru>");
  3653. MODULE_LICENSE("GPL");