dib8000.c 121 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972
  1. /*
  2. * Linux-DVB Driver for DiBcom's DiB8000 chip (ISDB-T).
  3. *
  4. * Copyright (C) 2009 DiBcom (http://www.dibcom.fr/)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation, version 2.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/slab.h>
  12. #include <linux/i2c.h>
  13. #include <linux/mutex.h>
  14. #include "dvb_math.h"
  15. #include "dvb_frontend.h"
  16. #include "dib8000.h"
  17. #define LAYER_ALL -1
  18. #define LAYER_A 1
  19. #define LAYER_B 2
  20. #define LAYER_C 3
  21. #define MAX_NUMBER_OF_FRONTENDS 6
  22. /* #define DIB8000_AGC_FREEZE */
  23. static int debug;
  24. module_param(debug, int, 0644);
  25. MODULE_PARM_DESC(debug, "turn on debugging (default: 0)");
  26. #define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiB8000: "); printk(args); printk("\n"); } } while (0)
  27. struct i2c_device {
  28. struct i2c_adapter *adap;
  29. u8 addr;
  30. u8 *i2c_write_buffer;
  31. u8 *i2c_read_buffer;
  32. struct mutex *i2c_buffer_lock;
  33. };
  34. enum param_loop_step {
  35. LOOP_TUNE_1,
  36. LOOP_TUNE_2
  37. };
  38. enum dib8000_autosearch_step {
  39. AS_START = 0,
  40. AS_SEARCHING_FFT,
  41. AS_SEARCHING_GUARD,
  42. AS_DONE = 100,
  43. };
  44. enum timeout_mode {
  45. SYMBOL_DEPENDENT_OFF = 0,
  46. SYMBOL_DEPENDENT_ON,
  47. };
  48. struct dib8000_state {
  49. struct dib8000_config cfg;
  50. struct i2c_device i2c;
  51. struct dibx000_i2c_master i2c_master;
  52. u16 wbd_ref;
  53. u8 current_band;
  54. u32 current_bandwidth;
  55. struct dibx000_agc_config *current_agc;
  56. u32 timf;
  57. u32 timf_default;
  58. u8 div_force_off:1;
  59. u8 div_state:1;
  60. u16 div_sync_wait;
  61. u8 agc_state;
  62. u8 differential_constellation;
  63. u8 diversity_onoff;
  64. s16 ber_monitored_layer;
  65. u16 gpio_dir;
  66. u16 gpio_val;
  67. u16 revision;
  68. u8 isdbt_cfg_loaded;
  69. enum frontend_tune_state tune_state;
  70. s32 status;
  71. struct dvb_frontend *fe[MAX_NUMBER_OF_FRONTENDS];
  72. /* for the I2C transfer */
  73. struct i2c_msg msg[2];
  74. u8 i2c_write_buffer[4];
  75. u8 i2c_read_buffer[2];
  76. struct mutex i2c_buffer_lock;
  77. u8 input_mode_mpeg;
  78. u16 tuner_enable;
  79. struct i2c_adapter dib8096p_tuner_adap;
  80. u16 current_demod_bw;
  81. u16 seg_mask;
  82. u16 seg_diff_mask;
  83. u16 mode;
  84. u8 layer_b_nb_seg;
  85. u8 layer_c_nb_seg;
  86. u8 channel_parameters_set;
  87. u16 autosearch_state;
  88. u16 found_nfft;
  89. u16 found_guard;
  90. u8 subchannel;
  91. u8 symbol_duration;
  92. u32 timeout;
  93. u8 longest_intlv_layer;
  94. u16 output_mode;
  95. #ifdef DIB8000_AGC_FREEZE
  96. u16 agc1_max;
  97. u16 agc1_min;
  98. u16 agc2_max;
  99. u16 agc2_min;
  100. #endif
  101. };
  102. enum dib8000_power_mode {
  103. DIB8000_POWER_ALL = 0,
  104. DIB8000_POWER_INTERFACE_ONLY,
  105. };
  106. static u16 dib8000_i2c_read16(struct i2c_device *i2c, u16 reg)
  107. {
  108. u16 ret;
  109. struct i2c_msg msg[2] = {
  110. {.addr = i2c->addr >> 1, .flags = 0, .len = 2},
  111. {.addr = i2c->addr >> 1, .flags = I2C_M_RD, .len = 2},
  112. };
  113. if (mutex_lock_interruptible(i2c->i2c_buffer_lock) < 0) {
  114. dprintk("could not acquire lock");
  115. return 0;
  116. }
  117. msg[0].buf = i2c->i2c_write_buffer;
  118. msg[0].buf[0] = reg >> 8;
  119. msg[0].buf[1] = reg & 0xff;
  120. msg[1].buf = i2c->i2c_read_buffer;
  121. if (i2c_transfer(i2c->adap, msg, 2) != 2)
  122. dprintk("i2c read error on %d", reg);
  123. ret = (msg[1].buf[0] << 8) | msg[1].buf[1];
  124. mutex_unlock(i2c->i2c_buffer_lock);
  125. return ret;
  126. }
  127. static u16 dib8000_read_word(struct dib8000_state *state, u16 reg)
  128. {
  129. u16 ret;
  130. if (mutex_lock_interruptible(&state->i2c_buffer_lock) < 0) {
  131. dprintk("could not acquire lock");
  132. return 0;
  133. }
  134. state->i2c_write_buffer[0] = reg >> 8;
  135. state->i2c_write_buffer[1] = reg & 0xff;
  136. memset(state->msg, 0, 2 * sizeof(struct i2c_msg));
  137. state->msg[0].addr = state->i2c.addr >> 1;
  138. state->msg[0].flags = 0;
  139. state->msg[0].buf = state->i2c_write_buffer;
  140. state->msg[0].len = 2;
  141. state->msg[1].addr = state->i2c.addr >> 1;
  142. state->msg[1].flags = I2C_M_RD;
  143. state->msg[1].buf = state->i2c_read_buffer;
  144. state->msg[1].len = 2;
  145. if (i2c_transfer(state->i2c.adap, state->msg, 2) != 2)
  146. dprintk("i2c read error on %d", reg);
  147. ret = (state->i2c_read_buffer[0] << 8) | state->i2c_read_buffer[1];
  148. mutex_unlock(&state->i2c_buffer_lock);
  149. return ret;
  150. }
  151. static u32 dib8000_read32(struct dib8000_state *state, u16 reg)
  152. {
  153. u16 rw[2];
  154. rw[0] = dib8000_read_word(state, reg + 0);
  155. rw[1] = dib8000_read_word(state, reg + 1);
  156. return ((rw[0] << 16) | (rw[1]));
  157. }
  158. static int dib8000_i2c_write16(struct i2c_device *i2c, u16 reg, u16 val)
  159. {
  160. struct i2c_msg msg = {.addr = i2c->addr >> 1, .flags = 0, .len = 4};
  161. int ret = 0;
  162. if (mutex_lock_interruptible(i2c->i2c_buffer_lock) < 0) {
  163. dprintk("could not acquire lock");
  164. return -EINVAL;
  165. }
  166. msg.buf = i2c->i2c_write_buffer;
  167. msg.buf[0] = (reg >> 8) & 0xff;
  168. msg.buf[1] = reg & 0xff;
  169. msg.buf[2] = (val >> 8) & 0xff;
  170. msg.buf[3] = val & 0xff;
  171. ret = i2c_transfer(i2c->adap, &msg, 1) != 1 ? -EREMOTEIO : 0;
  172. mutex_unlock(i2c->i2c_buffer_lock);
  173. return ret;
  174. }
  175. static int dib8000_write_word(struct dib8000_state *state, u16 reg, u16 val)
  176. {
  177. int ret;
  178. if (mutex_lock_interruptible(&state->i2c_buffer_lock) < 0) {
  179. dprintk("could not acquire lock");
  180. return -EINVAL;
  181. }
  182. state->i2c_write_buffer[0] = (reg >> 8) & 0xff;
  183. state->i2c_write_buffer[1] = reg & 0xff;
  184. state->i2c_write_buffer[2] = (val >> 8) & 0xff;
  185. state->i2c_write_buffer[3] = val & 0xff;
  186. memset(&state->msg[0], 0, sizeof(struct i2c_msg));
  187. state->msg[0].addr = state->i2c.addr >> 1;
  188. state->msg[0].flags = 0;
  189. state->msg[0].buf = state->i2c_write_buffer;
  190. state->msg[0].len = 4;
  191. ret = (i2c_transfer(state->i2c.adap, state->msg, 1) != 1 ?
  192. -EREMOTEIO : 0);
  193. mutex_unlock(&state->i2c_buffer_lock);
  194. return ret;
  195. }
  196. static const s16 coeff_2k_sb_1seg_dqpsk[8] = {
  197. (769 << 5) | 0x0a, (745 << 5) | 0x03, (595 << 5) | 0x0d, (769 << 5) | 0x0a, (920 << 5) | 0x09, (784 << 5) | 0x02, (519 << 5) | 0x0c,
  198. (920 << 5) | 0x09
  199. };
  200. static const s16 coeff_2k_sb_1seg[8] = {
  201. (692 << 5) | 0x0b, (683 << 5) | 0x01, (519 << 5) | 0x09, (692 << 5) | 0x0b, 0 | 0x1f, 0 | 0x1f, 0 | 0x1f, 0 | 0x1f
  202. };
  203. static const s16 coeff_2k_sb_3seg_0dqpsk_1dqpsk[8] = {
  204. (832 << 5) | 0x10, (912 << 5) | 0x05, (900 << 5) | 0x12, (832 << 5) | 0x10, (-931 << 5) | 0x0f, (912 << 5) | 0x04, (807 << 5) | 0x11,
  205. (-931 << 5) | 0x0f
  206. };
  207. static const s16 coeff_2k_sb_3seg_0dqpsk[8] = {
  208. (622 << 5) | 0x0c, (941 << 5) | 0x04, (796 << 5) | 0x10, (622 << 5) | 0x0c, (982 << 5) | 0x0c, (519 << 5) | 0x02, (572 << 5) | 0x0e,
  209. (982 << 5) | 0x0c
  210. };
  211. static const s16 coeff_2k_sb_3seg_1dqpsk[8] = {
  212. (699 << 5) | 0x14, (607 << 5) | 0x04, (944 << 5) | 0x13, (699 << 5) | 0x14, (-720 << 5) | 0x0d, (640 << 5) | 0x03, (866 << 5) | 0x12,
  213. (-720 << 5) | 0x0d
  214. };
  215. static const s16 coeff_2k_sb_3seg[8] = {
  216. (664 << 5) | 0x0c, (925 << 5) | 0x03, (937 << 5) | 0x10, (664 << 5) | 0x0c, (-610 << 5) | 0x0a, (697 << 5) | 0x01, (836 << 5) | 0x0e,
  217. (-610 << 5) | 0x0a
  218. };
  219. static const s16 coeff_4k_sb_1seg_dqpsk[8] = {
  220. (-955 << 5) | 0x0e, (687 << 5) | 0x04, (818 << 5) | 0x10, (-955 << 5) | 0x0e, (-922 << 5) | 0x0d, (750 << 5) | 0x03, (665 << 5) | 0x0f,
  221. (-922 << 5) | 0x0d
  222. };
  223. static const s16 coeff_4k_sb_1seg[8] = {
  224. (638 << 5) | 0x0d, (683 << 5) | 0x02, (638 << 5) | 0x0d, (638 << 5) | 0x0d, (-655 << 5) | 0x0a, (517 << 5) | 0x00, (698 << 5) | 0x0d,
  225. (-655 << 5) | 0x0a
  226. };
  227. static const s16 coeff_4k_sb_3seg_0dqpsk_1dqpsk[8] = {
  228. (-707 << 5) | 0x14, (910 << 5) | 0x06, (889 << 5) | 0x16, (-707 << 5) | 0x14, (-958 << 5) | 0x13, (993 << 5) | 0x05, (523 << 5) | 0x14,
  229. (-958 << 5) | 0x13
  230. };
  231. static const s16 coeff_4k_sb_3seg_0dqpsk[8] = {
  232. (-723 << 5) | 0x13, (910 << 5) | 0x05, (777 << 5) | 0x14, (-723 << 5) | 0x13, (-568 << 5) | 0x0f, (547 << 5) | 0x03, (696 << 5) | 0x12,
  233. (-568 << 5) | 0x0f
  234. };
  235. static const s16 coeff_4k_sb_3seg_1dqpsk[8] = {
  236. (-940 << 5) | 0x15, (607 << 5) | 0x05, (915 << 5) | 0x16, (-940 << 5) | 0x15, (-848 << 5) | 0x13, (683 << 5) | 0x04, (543 << 5) | 0x14,
  237. (-848 << 5) | 0x13
  238. };
  239. static const s16 coeff_4k_sb_3seg[8] = {
  240. (612 << 5) | 0x12, (910 << 5) | 0x04, (864 << 5) | 0x14, (612 << 5) | 0x12, (-869 << 5) | 0x13, (683 << 5) | 0x02, (869 << 5) | 0x12,
  241. (-869 << 5) | 0x13
  242. };
  243. static const s16 coeff_8k_sb_1seg_dqpsk[8] = {
  244. (-835 << 5) | 0x12, (684 << 5) | 0x05, (735 << 5) | 0x14, (-835 << 5) | 0x12, (-598 << 5) | 0x10, (781 << 5) | 0x04, (739 << 5) | 0x13,
  245. (-598 << 5) | 0x10
  246. };
  247. static const s16 coeff_8k_sb_1seg[8] = {
  248. (673 << 5) | 0x0f, (683 << 5) | 0x03, (808 << 5) | 0x12, (673 << 5) | 0x0f, (585 << 5) | 0x0f, (512 << 5) | 0x01, (780 << 5) | 0x0f,
  249. (585 << 5) | 0x0f
  250. };
  251. static const s16 coeff_8k_sb_3seg_0dqpsk_1dqpsk[8] = {
  252. (863 << 5) | 0x17, (930 << 5) | 0x07, (878 << 5) | 0x19, (863 << 5) | 0x17, (0 << 5) | 0x14, (521 << 5) | 0x05, (980 << 5) | 0x18,
  253. (0 << 5) | 0x14
  254. };
  255. static const s16 coeff_8k_sb_3seg_0dqpsk[8] = {
  256. (-924 << 5) | 0x17, (910 << 5) | 0x06, (774 << 5) | 0x17, (-924 << 5) | 0x17, (-877 << 5) | 0x15, (565 << 5) | 0x04, (553 << 5) | 0x15,
  257. (-877 << 5) | 0x15
  258. };
  259. static const s16 coeff_8k_sb_3seg_1dqpsk[8] = {
  260. (-921 << 5) | 0x19, (607 << 5) | 0x06, (881 << 5) | 0x19, (-921 << 5) | 0x19, (-921 << 5) | 0x14, (713 << 5) | 0x05, (1018 << 5) | 0x18,
  261. (-921 << 5) | 0x14
  262. };
  263. static const s16 coeff_8k_sb_3seg[8] = {
  264. (514 << 5) | 0x14, (910 << 5) | 0x05, (861 << 5) | 0x17, (514 << 5) | 0x14, (690 << 5) | 0x14, (683 << 5) | 0x03, (662 << 5) | 0x15,
  265. (690 << 5) | 0x14
  266. };
  267. static const s16 ana_fe_coeff_3seg[24] = {
  268. 81, 80, 78, 74, 68, 61, 54, 45, 37, 28, 19, 11, 4, 1022, 1017, 1013, 1010, 1008, 1008, 1008, 1008, 1010, 1014, 1017
  269. };
  270. static const s16 ana_fe_coeff_1seg[24] = {
  271. 249, 226, 164, 82, 5, 981, 970, 988, 1018, 20, 31, 26, 8, 1012, 1000, 1018, 1012, 8, 15, 14, 9, 3, 1017, 1003
  272. };
  273. static const s16 ana_fe_coeff_13seg[24] = {
  274. 396, 305, 105, -51, -77, -12, 41, 31, -11, -30, -11, 14, 15, -2, -13, -7, 5, 8, 1, -6, -7, -3, 0, 1
  275. };
  276. static u16 fft_to_mode(struct dib8000_state *state)
  277. {
  278. u16 mode;
  279. switch (state->fe[0]->dtv_property_cache.transmission_mode) {
  280. case TRANSMISSION_MODE_2K:
  281. mode = 1;
  282. break;
  283. case TRANSMISSION_MODE_4K:
  284. mode = 2;
  285. break;
  286. default:
  287. case TRANSMISSION_MODE_AUTO:
  288. case TRANSMISSION_MODE_8K:
  289. mode = 3;
  290. break;
  291. }
  292. return mode;
  293. }
  294. static void dib8000_set_acquisition_mode(struct dib8000_state *state)
  295. {
  296. u16 nud = dib8000_read_word(state, 298);
  297. nud |= (1 << 3) | (1 << 0);
  298. dprintk("acquisition mode activated");
  299. dib8000_write_word(state, 298, nud);
  300. }
  301. static int dib8000_set_output_mode(struct dvb_frontend *fe, int mode)
  302. {
  303. struct dib8000_state *state = fe->demodulator_priv;
  304. u16 outreg, fifo_threshold, smo_mode, sram = 0x0205; /* by default SDRAM deintlv is enabled */
  305. state->output_mode = mode;
  306. outreg = 0;
  307. fifo_threshold = 1792;
  308. smo_mode = (dib8000_read_word(state, 299) & 0x0050) | (1 << 1);
  309. dprintk("-I- Setting output mode for demod %p to %d",
  310. &state->fe[0], mode);
  311. switch (mode) {
  312. case OUTMODE_MPEG2_PAR_GATED_CLK: // STBs with parallel gated clock
  313. outreg = (1 << 10); /* 0x0400 */
  314. break;
  315. case OUTMODE_MPEG2_PAR_CONT_CLK: // STBs with parallel continues clock
  316. outreg = (1 << 10) | (1 << 6); /* 0x0440 */
  317. break;
  318. case OUTMODE_MPEG2_SERIAL: // STBs with serial input
  319. outreg = (1 << 10) | (2 << 6) | (0 << 1); /* 0x0482 */
  320. break;
  321. case OUTMODE_DIVERSITY:
  322. if (state->cfg.hostbus_diversity) {
  323. outreg = (1 << 10) | (4 << 6); /* 0x0500 */
  324. sram &= 0xfdff;
  325. } else
  326. sram |= 0x0c00;
  327. break;
  328. case OUTMODE_MPEG2_FIFO: // e.g. USB feeding
  329. smo_mode |= (3 << 1);
  330. fifo_threshold = 512;
  331. outreg = (1 << 10) | (5 << 6);
  332. break;
  333. case OUTMODE_HIGH_Z: // disable
  334. outreg = 0;
  335. break;
  336. case OUTMODE_ANALOG_ADC:
  337. outreg = (1 << 10) | (3 << 6);
  338. dib8000_set_acquisition_mode(state);
  339. break;
  340. default:
  341. dprintk("Unhandled output_mode passed to be set for demod %p",
  342. &state->fe[0]);
  343. return -EINVAL;
  344. }
  345. if (state->cfg.output_mpeg2_in_188_bytes)
  346. smo_mode |= (1 << 5);
  347. dib8000_write_word(state, 299, smo_mode);
  348. dib8000_write_word(state, 300, fifo_threshold); /* synchronous fread */
  349. dib8000_write_word(state, 1286, outreg);
  350. dib8000_write_word(state, 1291, sram);
  351. return 0;
  352. }
  353. static int dib8000_set_diversity_in(struct dvb_frontend *fe, int onoff)
  354. {
  355. struct dib8000_state *state = fe->demodulator_priv;
  356. u16 tmp, sync_wait = dib8000_read_word(state, 273) & 0xfff0;
  357. dprintk("set diversity input to %i", onoff);
  358. if (!state->differential_constellation) {
  359. dib8000_write_word(state, 272, 1 << 9); //dvsy_off_lmod4 = 1
  360. dib8000_write_word(state, 273, sync_wait | (1 << 2) | 2); // sync_enable = 1; comb_mode = 2
  361. } else {
  362. dib8000_write_word(state, 272, 0); //dvsy_off_lmod4 = 0
  363. dib8000_write_word(state, 273, sync_wait); // sync_enable = 0; comb_mode = 0
  364. }
  365. state->diversity_onoff = onoff;
  366. switch (onoff) {
  367. case 0: /* only use the internal way - not the diversity input */
  368. dib8000_write_word(state, 270, 1);
  369. dib8000_write_word(state, 271, 0);
  370. break;
  371. case 1: /* both ways */
  372. dib8000_write_word(state, 270, 6);
  373. dib8000_write_word(state, 271, 6);
  374. break;
  375. case 2: /* only the diversity input */
  376. dib8000_write_word(state, 270, 0);
  377. dib8000_write_word(state, 271, 1);
  378. break;
  379. }
  380. if (state->revision == 0x8002) {
  381. tmp = dib8000_read_word(state, 903);
  382. dib8000_write_word(state, 903, tmp & ~(1 << 3));
  383. msleep(30);
  384. dib8000_write_word(state, 903, tmp | (1 << 3));
  385. }
  386. return 0;
  387. }
  388. static void dib8000_set_power_mode(struct dib8000_state *state, enum dib8000_power_mode mode)
  389. {
  390. /* by default everything is going to be powered off */
  391. u16 reg_774 = 0x3fff, reg_775 = 0xffff, reg_776 = 0xffff,
  392. reg_900 = (dib8000_read_word(state, 900) & 0xfffc) | 0x3,
  393. reg_1280;
  394. if (state->revision != 0x8090)
  395. reg_1280 = (dib8000_read_word(state, 1280) & 0x00ff) | 0xff00;
  396. else
  397. reg_1280 = (dib8000_read_word(state, 1280) & 0x707f) | 0x8f80;
  398. /* now, depending on the requested mode, we power on */
  399. switch (mode) {
  400. /* power up everything in the demod */
  401. case DIB8000_POWER_ALL:
  402. reg_774 = 0x0000;
  403. reg_775 = 0x0000;
  404. reg_776 = 0x0000;
  405. reg_900 &= 0xfffc;
  406. if (state->revision != 0x8090)
  407. reg_1280 &= 0x00ff;
  408. else
  409. reg_1280 &= 0x707f;
  410. break;
  411. case DIB8000_POWER_INTERFACE_ONLY:
  412. if (state->revision != 0x8090)
  413. reg_1280 &= 0x00ff;
  414. else
  415. reg_1280 &= 0xfa7b;
  416. break;
  417. }
  418. dprintk("powermode : 774 : %x ; 775 : %x; 776 : %x ; 900 : %x; 1280 : %x", reg_774, reg_775, reg_776, reg_900, reg_1280);
  419. dib8000_write_word(state, 774, reg_774);
  420. dib8000_write_word(state, 775, reg_775);
  421. dib8000_write_word(state, 776, reg_776);
  422. dib8000_write_word(state, 900, reg_900);
  423. dib8000_write_word(state, 1280, reg_1280);
  424. }
  425. static int dib8000_set_adc_state(struct dib8000_state *state, enum dibx000_adc_states no)
  426. {
  427. int ret = 0;
  428. u16 reg, reg_907 = dib8000_read_word(state, 907);
  429. u16 reg_908 = dib8000_read_word(state, 908);
  430. switch (no) {
  431. case DIBX000_SLOW_ADC_ON:
  432. if (state->revision != 0x8090) {
  433. reg_908 |= (1 << 1) | (1 << 0);
  434. ret |= dib8000_write_word(state, 908, reg_908);
  435. reg_908 &= ~(1 << 1);
  436. } else {
  437. reg = dib8000_read_word(state, 1925);
  438. /* en_slowAdc = 1 & reset_sladc = 1 */
  439. dib8000_write_word(state, 1925, reg |
  440. (1<<4) | (1<<2));
  441. /* read acces to make it works... strange ... */
  442. reg = dib8000_read_word(state, 1925);
  443. msleep(20);
  444. /* en_slowAdc = 1 & reset_sladc = 0 */
  445. dib8000_write_word(state, 1925, reg & ~(1<<4));
  446. reg = dib8000_read_word(state, 921) & ~((0x3 << 14)
  447. | (0x3 << 12));
  448. /* ref = Vin1 => Vbg ; sel = Vin0 or Vin3 ;
  449. (Vin2 = Vcm) */
  450. dib8000_write_word(state, 921, reg | (1 << 14)
  451. | (3 << 12));
  452. }
  453. break;
  454. case DIBX000_SLOW_ADC_OFF:
  455. if (state->revision == 0x8090) {
  456. reg = dib8000_read_word(state, 1925);
  457. /* reset_sladc = 1 en_slowAdc = 0 */
  458. dib8000_write_word(state, 1925,
  459. (reg & ~(1<<2)) | (1<<4));
  460. }
  461. reg_908 |= (1 << 1) | (1 << 0);
  462. break;
  463. case DIBX000_ADC_ON:
  464. reg_907 &= 0x0fff;
  465. reg_908 &= 0x0003;
  466. break;
  467. case DIBX000_ADC_OFF: // leave the VBG voltage on
  468. reg_907 |= (1 << 14) | (1 << 13) | (1 << 12);
  469. reg_908 |= (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2);
  470. break;
  471. case DIBX000_VBG_ENABLE:
  472. reg_907 &= ~(1 << 15);
  473. break;
  474. case DIBX000_VBG_DISABLE:
  475. reg_907 |= (1 << 15);
  476. break;
  477. default:
  478. break;
  479. }
  480. ret |= dib8000_write_word(state, 907, reg_907);
  481. ret |= dib8000_write_word(state, 908, reg_908);
  482. return ret;
  483. }
  484. static int dib8000_set_bandwidth(struct dvb_frontend *fe, u32 bw)
  485. {
  486. struct dib8000_state *state = fe->demodulator_priv;
  487. u32 timf;
  488. if (bw == 0)
  489. bw = 6000;
  490. if (state->timf == 0) {
  491. dprintk("using default timf");
  492. timf = state->timf_default;
  493. } else {
  494. dprintk("using updated timf");
  495. timf = state->timf;
  496. }
  497. dib8000_write_word(state, 29, (u16) ((timf >> 16) & 0xffff));
  498. dib8000_write_word(state, 30, (u16) ((timf) & 0xffff));
  499. return 0;
  500. }
  501. static int dib8000_sad_calib(struct dib8000_state *state)
  502. {
  503. u8 sad_sel = 3;
  504. if (state->revision == 0x8090) {
  505. dib8000_write_word(state, 922, (sad_sel << 2));
  506. dib8000_write_word(state, 923, 2048);
  507. dib8000_write_word(state, 922, (sad_sel << 2) | 0x1);
  508. dib8000_write_word(state, 922, (sad_sel << 2));
  509. } else {
  510. /* internal */
  511. dib8000_write_word(state, 923, (0 << 1) | (0 << 0));
  512. dib8000_write_word(state, 924, 776);
  513. /* do the calibration */
  514. dib8000_write_word(state, 923, (1 << 0));
  515. dib8000_write_word(state, 923, (0 << 0));
  516. }
  517. msleep(1);
  518. return 0;
  519. }
  520. int dib8000_set_wbd_ref(struct dvb_frontend *fe, u16 value)
  521. {
  522. struct dib8000_state *state = fe->demodulator_priv;
  523. if (value > 4095)
  524. value = 4095;
  525. state->wbd_ref = value;
  526. return dib8000_write_word(state, 106, value);
  527. }
  528. EXPORT_SYMBOL(dib8000_set_wbd_ref);
  529. static void dib8000_reset_pll_common(struct dib8000_state *state, const struct dibx000_bandwidth_config *bw)
  530. {
  531. dprintk("ifreq: %d %x, inversion: %d", bw->ifreq, bw->ifreq, bw->ifreq >> 25);
  532. if (state->revision != 0x8090) {
  533. dib8000_write_word(state, 23,
  534. (u16) (((bw->internal * 1000) >> 16) & 0xffff));
  535. dib8000_write_word(state, 24,
  536. (u16) ((bw->internal * 1000) & 0xffff));
  537. } else {
  538. dib8000_write_word(state, 23, (u16) (((bw->internal / 2 * 1000) >> 16) & 0xffff));
  539. dib8000_write_word(state, 24,
  540. (u16) ((bw->internal / 2 * 1000) & 0xffff));
  541. }
  542. dib8000_write_word(state, 27, (u16) ((bw->ifreq >> 16) & 0x01ff));
  543. dib8000_write_word(state, 28, (u16) (bw->ifreq & 0xffff));
  544. dib8000_write_word(state, 26, (u16) ((bw->ifreq >> 25) & 0x0003));
  545. if (state->revision != 0x8090)
  546. dib8000_write_word(state, 922, bw->sad_cfg);
  547. }
  548. static void dib8000_reset_pll(struct dib8000_state *state)
  549. {
  550. const struct dibx000_bandwidth_config *pll = state->cfg.pll;
  551. u16 clk_cfg1, reg;
  552. if (state->revision != 0x8090) {
  553. dib8000_write_word(state, 901,
  554. (pll->pll_prediv << 8) | (pll->pll_ratio << 0));
  555. clk_cfg1 = (1 << 10) | (0 << 9) | (pll->IO_CLK_en_core << 8) |
  556. (pll->bypclk_div << 5) | (pll->enable_refdiv << 4) |
  557. (1 << 3) | (pll->pll_range << 1) |
  558. (pll->pll_reset << 0);
  559. dib8000_write_word(state, 902, clk_cfg1);
  560. clk_cfg1 = (clk_cfg1 & 0xfff7) | (pll->pll_bypass << 3);
  561. dib8000_write_word(state, 902, clk_cfg1);
  562. dprintk("clk_cfg1: 0x%04x", clk_cfg1);
  563. /* smpl_cfg: P_refclksel=2, P_ensmplsel=1 nodivsmpl=1 */
  564. if (state->cfg.pll->ADClkSrc == 0)
  565. dib8000_write_word(state, 904,
  566. (0 << 15) | (0 << 12) | (0 << 10) |
  567. (pll->modulo << 8) |
  568. (pll->ADClkSrc << 7) | (0 << 1));
  569. else if (state->cfg.refclksel != 0)
  570. dib8000_write_word(state, 904, (0 << 15) | (1 << 12) |
  571. ((state->cfg.refclksel & 0x3) << 10) |
  572. (pll->modulo << 8) |
  573. (pll->ADClkSrc << 7) | (0 << 1));
  574. else
  575. dib8000_write_word(state, 904, (0 << 15) | (1 << 12) |
  576. (3 << 10) | (pll->modulo << 8) |
  577. (pll->ADClkSrc << 7) | (0 << 1));
  578. } else {
  579. dib8000_write_word(state, 1856, (!pll->pll_reset<<13) |
  580. (pll->pll_range<<12) | (pll->pll_ratio<<6) |
  581. (pll->pll_prediv));
  582. reg = dib8000_read_word(state, 1857);
  583. dib8000_write_word(state, 1857, reg|(!pll->pll_bypass<<15));
  584. reg = dib8000_read_word(state, 1858); /* Force clk out pll /2 */
  585. dib8000_write_word(state, 1858, reg | 1);
  586. dib8000_write_word(state, 904, (pll->modulo << 8));
  587. }
  588. dib8000_reset_pll_common(state, pll);
  589. }
  590. int dib8000_update_pll(struct dvb_frontend *fe,
  591. struct dibx000_bandwidth_config *pll, u32 bw, u8 ratio)
  592. {
  593. struct dib8000_state *state = fe->demodulator_priv;
  594. u16 reg_1857, reg_1856 = dib8000_read_word(state, 1856);
  595. u8 loopdiv, prediv, oldprediv = state->cfg.pll->pll_prediv ;
  596. u32 internal, xtal;
  597. /* get back old values */
  598. prediv = reg_1856 & 0x3f;
  599. loopdiv = (reg_1856 >> 6) & 0x3f;
  600. if ((pll == NULL) || (pll->pll_prediv == prediv &&
  601. pll->pll_ratio == loopdiv))
  602. return -EINVAL;
  603. dprintk("Updating pll (prediv: old = %d new = %d ; loopdiv : old = %d new = %d)", prediv, pll->pll_prediv, loopdiv, pll->pll_ratio);
  604. if (state->revision == 0x8090) {
  605. reg_1856 &= 0xf000;
  606. reg_1857 = dib8000_read_word(state, 1857);
  607. /* disable PLL */
  608. dib8000_write_word(state, 1857, reg_1857 & ~(1 << 15));
  609. dib8000_write_word(state, 1856, reg_1856 |
  610. ((pll->pll_ratio & 0x3f) << 6) |
  611. (pll->pll_prediv & 0x3f));
  612. /* write new system clk into P_sec_len */
  613. internal = dib8000_read32(state, 23) / 1000;
  614. dprintk("Old Internal = %d", internal);
  615. xtal = 2 * (internal / loopdiv) * prediv;
  616. internal = 1000 * (xtal/pll->pll_prediv) * pll->pll_ratio;
  617. dprintk("Xtal = %d , New Fmem = %d New Fdemod = %d, New Fsampling = %d", xtal, internal/1000, internal/2000, internal/8000);
  618. dprintk("New Internal = %d", internal);
  619. dib8000_write_word(state, 23,
  620. (u16) (((internal / 2) >> 16) & 0xffff));
  621. dib8000_write_word(state, 24, (u16) ((internal / 2) & 0xffff));
  622. /* enable PLL */
  623. dib8000_write_word(state, 1857, reg_1857 | (1 << 15));
  624. while (((dib8000_read_word(state, 1856)>>15)&0x1) != 1)
  625. dprintk("Waiting for PLL to lock");
  626. /* verify */
  627. reg_1856 = dib8000_read_word(state, 1856);
  628. dprintk("PLL Updated with prediv = %d and loopdiv = %d",
  629. reg_1856&0x3f, (reg_1856>>6)&0x3f);
  630. } else {
  631. if (bw != state->current_demod_bw) {
  632. /** Bandwidth change => force PLL update **/
  633. dprintk("PLL: Bandwidth Change %d MHz -> %d MHz (prediv: %d->%d)", state->current_demod_bw / 1000, bw / 1000, oldprediv, state->cfg.pll->pll_prediv);
  634. if (state->cfg.pll->pll_prediv != oldprediv) {
  635. /** Full PLL change only if prediv is changed **/
  636. /** full update => bypass and reconfigure **/
  637. dprintk("PLL: New Setting for %d MHz Bandwidth (prediv: %d, ratio: %d)", bw/1000, state->cfg.pll->pll_prediv, state->cfg.pll->pll_ratio);
  638. dib8000_write_word(state, 902, dib8000_read_word(state, 902) | (1<<3)); /* bypass PLL */
  639. dib8000_reset_pll(state);
  640. dib8000_write_word(state, 898, 0x0004); /* sad */
  641. } else
  642. ratio = state->cfg.pll->pll_ratio;
  643. state->current_demod_bw = bw;
  644. }
  645. if (ratio != 0) {
  646. /** ratio update => only change ratio **/
  647. dprintk("PLL: Update ratio (prediv: %d, ratio: %d)", state->cfg.pll->pll_prediv, ratio);
  648. dib8000_write_word(state, 901, (state->cfg.pll->pll_prediv << 8) | (ratio << 0)); /* only the PLL ratio is updated. */
  649. }
  650. }
  651. return 0;
  652. }
  653. EXPORT_SYMBOL(dib8000_update_pll);
  654. static int dib8000_reset_gpio(struct dib8000_state *st)
  655. {
  656. /* reset the GPIOs */
  657. dib8000_write_word(st, 1029, st->cfg.gpio_dir);
  658. dib8000_write_word(st, 1030, st->cfg.gpio_val);
  659. /* TODO 782 is P_gpio_od */
  660. dib8000_write_word(st, 1032, st->cfg.gpio_pwm_pos);
  661. dib8000_write_word(st, 1037, st->cfg.pwm_freq_div);
  662. return 0;
  663. }
  664. static int dib8000_cfg_gpio(struct dib8000_state *st, u8 num, u8 dir, u8 val)
  665. {
  666. st->cfg.gpio_dir = dib8000_read_word(st, 1029);
  667. st->cfg.gpio_dir &= ~(1 << num); /* reset the direction bit */
  668. st->cfg.gpio_dir |= (dir & 0x1) << num; /* set the new direction */
  669. dib8000_write_word(st, 1029, st->cfg.gpio_dir);
  670. st->cfg.gpio_val = dib8000_read_word(st, 1030);
  671. st->cfg.gpio_val &= ~(1 << num); /* reset the direction bit */
  672. st->cfg.gpio_val |= (val & 0x01) << num; /* set the new value */
  673. dib8000_write_word(st, 1030, st->cfg.gpio_val);
  674. dprintk("gpio dir: %x: gpio val: %x", st->cfg.gpio_dir, st->cfg.gpio_val);
  675. return 0;
  676. }
  677. int dib8000_set_gpio(struct dvb_frontend *fe, u8 num, u8 dir, u8 val)
  678. {
  679. struct dib8000_state *state = fe->demodulator_priv;
  680. return dib8000_cfg_gpio(state, num, dir, val);
  681. }
  682. EXPORT_SYMBOL(dib8000_set_gpio);
  683. static const u16 dib8000_defaults[] = {
  684. /* auto search configuration - lock0 by default waiting
  685. * for cpil_lock; lock1 cpil_lock; lock2 tmcc_sync_lock */
  686. 3, 7,
  687. 0x0004,
  688. 0x0400,
  689. 0x0814,
  690. 12, 11,
  691. 0x001b,
  692. 0x7740,
  693. 0x005b,
  694. 0x8d80,
  695. 0x01c9,
  696. 0xc380,
  697. 0x0000,
  698. 0x0080,
  699. 0x0000,
  700. 0x0090,
  701. 0x0001,
  702. 0xd4c0,
  703. /*1, 32,
  704. 0x6680 // P_corm_thres Lock algorithms configuration */
  705. 11, 80, /* set ADC level to -16 */
  706. (1 << 13) - 825 - 117,
  707. (1 << 13) - 837 - 117,
  708. (1 << 13) - 811 - 117,
  709. (1 << 13) - 766 - 117,
  710. (1 << 13) - 737 - 117,
  711. (1 << 13) - 693 - 117,
  712. (1 << 13) - 648 - 117,
  713. (1 << 13) - 619 - 117,
  714. (1 << 13) - 575 - 117,
  715. (1 << 13) - 531 - 117,
  716. (1 << 13) - 501 - 117,
  717. 4, 108,
  718. 0,
  719. 0,
  720. 0,
  721. 0,
  722. 1, 175,
  723. 0x0410,
  724. 1, 179,
  725. 8192, // P_fft_nb_to_cut
  726. 6, 181,
  727. 0x2800, // P_coff_corthres_ ( 2k 4k 8k ) 0x2800
  728. 0x2800,
  729. 0x2800,
  730. 0x2800, // P_coff_cpilthres_ ( 2k 4k 8k ) 0x2800
  731. 0x2800,
  732. 0x2800,
  733. 2, 193,
  734. 0x0666, // P_pha3_thres
  735. 0x0000, // P_cti_use_cpe, P_cti_use_prog
  736. 2, 205,
  737. 0x200f, // P_cspu_regul, P_cspu_win_cut
  738. 0x000f, // P_des_shift_work
  739. 5, 215,
  740. 0x023d, // P_adp_regul_cnt
  741. 0x00a4, // P_adp_noise_cnt
  742. 0x00a4, // P_adp_regul_ext
  743. 0x7ff0, // P_adp_noise_ext
  744. 0x3ccc, // P_adp_fil
  745. 1, 230,
  746. 0x0000, // P_2d_byp_ti_num
  747. 1, 263,
  748. 0x800, //P_equal_thres_wgn
  749. 1, 268,
  750. (2 << 9) | 39, // P_equal_ctrl_synchro, P_equal_speedmode
  751. 1, 270,
  752. 0x0001, // P_div_lock0_wait
  753. 1, 285,
  754. 0x0020, //p_fec_
  755. 1, 299,
  756. 0x0062, /* P_smo_mode, P_smo_rs_discard, P_smo_fifo_flush, P_smo_pid_parse, P_smo_error_discard */
  757. 1, 338,
  758. (1 << 12) | // P_ctrl_corm_thres4pre_freq_inh=1
  759. (1 << 10) |
  760. (0 << 9) | /* P_ctrl_pre_freq_inh=0 */
  761. (3 << 5) | /* P_ctrl_pre_freq_step=3 */
  762. (1 << 0), /* P_pre_freq_win_len=1 */
  763. 0,
  764. };
  765. static u16 dib8000_identify(struct i2c_device *client)
  766. {
  767. u16 value;
  768. //because of glitches sometimes
  769. value = dib8000_i2c_read16(client, 896);
  770. if ((value = dib8000_i2c_read16(client, 896)) != 0x01b3) {
  771. dprintk("wrong Vendor ID (read=0x%x)", value);
  772. return 0;
  773. }
  774. value = dib8000_i2c_read16(client, 897);
  775. if (value != 0x8000 && value != 0x8001 &&
  776. value != 0x8002 && value != 0x8090) {
  777. dprintk("wrong Device ID (%x)", value);
  778. return 0;
  779. }
  780. switch (value) {
  781. case 0x8000:
  782. dprintk("found DiB8000A");
  783. break;
  784. case 0x8001:
  785. dprintk("found DiB8000B");
  786. break;
  787. case 0x8002:
  788. dprintk("found DiB8000C");
  789. break;
  790. case 0x8090:
  791. dprintk("found DiB8096P");
  792. break;
  793. }
  794. return value;
  795. }
  796. static int dib8000_reset(struct dvb_frontend *fe)
  797. {
  798. struct dib8000_state *state = fe->demodulator_priv;
  799. if ((state->revision = dib8000_identify(&state->i2c)) == 0)
  800. return -EINVAL;
  801. /* sram lead in, rdy */
  802. if (state->revision != 0x8090)
  803. dib8000_write_word(state, 1287, 0x0003);
  804. if (state->revision == 0x8000)
  805. dprintk("error : dib8000 MA not supported");
  806. dibx000_reset_i2c_master(&state->i2c_master);
  807. dib8000_set_power_mode(state, DIB8000_POWER_ALL);
  808. /* always leave the VBG voltage on - it consumes almost nothing but takes a long time to start */
  809. dib8000_set_adc_state(state, DIBX000_ADC_OFF);
  810. /* restart all parts */
  811. dib8000_write_word(state, 770, 0xffff);
  812. dib8000_write_word(state, 771, 0xffff);
  813. dib8000_write_word(state, 772, 0xfffc);
  814. if (state->revision == 0x8090)
  815. dib8000_write_word(state, 1280, 0x0045);
  816. else
  817. dib8000_write_word(state, 1280, 0x004d);
  818. dib8000_write_word(state, 1281, 0x000c);
  819. dib8000_write_word(state, 770, 0x0000);
  820. dib8000_write_word(state, 771, 0x0000);
  821. dib8000_write_word(state, 772, 0x0000);
  822. dib8000_write_word(state, 898, 0x0004); // sad
  823. dib8000_write_word(state, 1280, 0x0000);
  824. dib8000_write_word(state, 1281, 0x0000);
  825. /* drives */
  826. if (state->revision != 0x8090) {
  827. if (state->cfg.drives)
  828. dib8000_write_word(state, 906, state->cfg.drives);
  829. else {
  830. dprintk("using standard PAD-drive-settings, please adjust settings in config-struct to be optimal.");
  831. /* min drive SDRAM - not optimal - adjust */
  832. dib8000_write_word(state, 906, 0x2d98);
  833. }
  834. }
  835. dib8000_reset_pll(state);
  836. if (state->revision != 0x8090)
  837. dib8000_write_word(state, 898, 0x0004);
  838. if (dib8000_reset_gpio(state) != 0)
  839. dprintk("GPIO reset was not successful.");
  840. if ((state->revision != 0x8090) &&
  841. (dib8000_set_output_mode(fe, OUTMODE_HIGH_Z) != 0))
  842. dprintk("OUTPUT_MODE could not be resetted.");
  843. state->current_agc = NULL;
  844. // P_iqc_alpha_pha, P_iqc_alpha_amp, P_iqc_dcc_alpha, ...
  845. /* P_iqc_ca2 = 0; P_iqc_impnc_on = 0; P_iqc_mode = 0; */
  846. if (state->cfg.pll->ifreq == 0)
  847. dib8000_write_word(state, 40, 0x0755); /* P_iqc_corr_inh = 0 enable IQcorr block */
  848. else
  849. dib8000_write_word(state, 40, 0x1f55); /* P_iqc_corr_inh = 1 disable IQcorr block */
  850. {
  851. u16 l = 0, r;
  852. const u16 *n;
  853. n = dib8000_defaults;
  854. l = *n++;
  855. while (l) {
  856. r = *n++;
  857. do {
  858. dib8000_write_word(state, r, *n++);
  859. r++;
  860. } while (--l);
  861. l = *n++;
  862. }
  863. }
  864. state->isdbt_cfg_loaded = 0;
  865. //div_cfg override for special configs
  866. if ((state->revision != 8090) && (state->cfg.div_cfg != 0))
  867. dib8000_write_word(state, 903, state->cfg.div_cfg);
  868. /* unforce divstr regardless whether i2c enumeration was done or not */
  869. dib8000_write_word(state, 1285, dib8000_read_word(state, 1285) & ~(1 << 1));
  870. dib8000_set_bandwidth(fe, 6000);
  871. dib8000_set_adc_state(state, DIBX000_SLOW_ADC_ON);
  872. dib8000_sad_calib(state);
  873. if (state->revision != 0x8090)
  874. dib8000_set_adc_state(state, DIBX000_SLOW_ADC_OFF);
  875. /* ber_rs_len = 3 */
  876. dib8000_write_word(state, 285, (dib8000_read_word(state, 285) & ~0x60) | (3 << 5));
  877. dib8000_set_power_mode(state, DIB8000_POWER_INTERFACE_ONLY);
  878. return 0;
  879. }
  880. static void dib8000_restart_agc(struct dib8000_state *state)
  881. {
  882. // P_restart_iqc & P_restart_agc
  883. dib8000_write_word(state, 770, 0x0a00);
  884. dib8000_write_word(state, 770, 0x0000);
  885. }
  886. static int dib8000_update_lna(struct dib8000_state *state)
  887. {
  888. u16 dyn_gain;
  889. if (state->cfg.update_lna) {
  890. // read dyn_gain here (because it is demod-dependent and not tuner)
  891. dyn_gain = dib8000_read_word(state, 390);
  892. if (state->cfg.update_lna(state->fe[0], dyn_gain)) {
  893. dib8000_restart_agc(state);
  894. return 1;
  895. }
  896. }
  897. return 0;
  898. }
  899. static int dib8000_set_agc_config(struct dib8000_state *state, u8 band)
  900. {
  901. struct dibx000_agc_config *agc = NULL;
  902. int i;
  903. u16 reg;
  904. if (state->current_band == band && state->current_agc != NULL)
  905. return 0;
  906. state->current_band = band;
  907. for (i = 0; i < state->cfg.agc_config_count; i++)
  908. if (state->cfg.agc[i].band_caps & band) {
  909. agc = &state->cfg.agc[i];
  910. break;
  911. }
  912. if (agc == NULL) {
  913. dprintk("no valid AGC configuration found for band 0x%02x", band);
  914. return -EINVAL;
  915. }
  916. state->current_agc = agc;
  917. /* AGC */
  918. dib8000_write_word(state, 76, agc->setup);
  919. dib8000_write_word(state, 77, agc->inv_gain);
  920. dib8000_write_word(state, 78, agc->time_stabiliz);
  921. dib8000_write_word(state, 101, (agc->alpha_level << 12) | agc->thlock);
  922. // Demod AGC loop configuration
  923. dib8000_write_word(state, 102, (agc->alpha_mant << 5) | agc->alpha_exp);
  924. dib8000_write_word(state, 103, (agc->beta_mant << 6) | agc->beta_exp);
  925. dprintk("WBD: ref: %d, sel: %d, active: %d, alpha: %d",
  926. state->wbd_ref != 0 ? state->wbd_ref : agc->wbd_ref, agc->wbd_sel, !agc->perform_agc_softsplit, agc->wbd_sel);
  927. /* AGC continued */
  928. if (state->wbd_ref != 0)
  929. dib8000_write_word(state, 106, state->wbd_ref);
  930. else // use default
  931. dib8000_write_word(state, 106, agc->wbd_ref);
  932. if (state->revision == 0x8090) {
  933. reg = dib8000_read_word(state, 922) & (0x3 << 2);
  934. dib8000_write_word(state, 922, reg | (agc->wbd_sel << 2));
  935. }
  936. dib8000_write_word(state, 107, (agc->wbd_alpha << 9) | (agc->perform_agc_softsplit << 8));
  937. dib8000_write_word(state, 108, agc->agc1_max);
  938. dib8000_write_word(state, 109, agc->agc1_min);
  939. dib8000_write_word(state, 110, agc->agc2_max);
  940. dib8000_write_word(state, 111, agc->agc2_min);
  941. dib8000_write_word(state, 112, (agc->agc1_pt1 << 8) | agc->agc1_pt2);
  942. dib8000_write_word(state, 113, (agc->agc1_slope1 << 8) | agc->agc1_slope2);
  943. dib8000_write_word(state, 114, (agc->agc2_pt1 << 8) | agc->agc2_pt2);
  944. dib8000_write_word(state, 115, (agc->agc2_slope1 << 8) | agc->agc2_slope2);
  945. dib8000_write_word(state, 75, agc->agc1_pt3);
  946. if (state->revision != 0x8090)
  947. dib8000_write_word(state, 923,
  948. (dib8000_read_word(state, 923) & 0xffe3) |
  949. (agc->wbd_inv << 4) | (agc->wbd_sel << 2));
  950. return 0;
  951. }
  952. void dib8000_pwm_agc_reset(struct dvb_frontend *fe)
  953. {
  954. struct dib8000_state *state = fe->demodulator_priv;
  955. dib8000_set_adc_state(state, DIBX000_ADC_ON);
  956. dib8000_set_agc_config(state, (unsigned char)(BAND_OF_FREQUENCY(fe->dtv_property_cache.frequency / 1000)));
  957. }
  958. EXPORT_SYMBOL(dib8000_pwm_agc_reset);
  959. static int dib8000_agc_soft_split(struct dib8000_state *state)
  960. {
  961. u16 agc, split_offset;
  962. if (!state->current_agc || !state->current_agc->perform_agc_softsplit || state->current_agc->split.max == 0)
  963. return FE_CALLBACK_TIME_NEVER;
  964. // n_agc_global
  965. agc = dib8000_read_word(state, 390);
  966. if (agc > state->current_agc->split.min_thres)
  967. split_offset = state->current_agc->split.min;
  968. else if (agc < state->current_agc->split.max_thres)
  969. split_offset = state->current_agc->split.max;
  970. else
  971. split_offset = state->current_agc->split.max *
  972. (agc - state->current_agc->split.min_thres) /
  973. (state->current_agc->split.max_thres - state->current_agc->split.min_thres);
  974. dprintk("AGC split_offset: %d", split_offset);
  975. // P_agc_force_split and P_agc_split_offset
  976. dib8000_write_word(state, 107, (dib8000_read_word(state, 107) & 0xff00) | split_offset);
  977. return 5000;
  978. }
  979. static int dib8000_agc_startup(struct dvb_frontend *fe)
  980. {
  981. struct dib8000_state *state = fe->demodulator_priv;
  982. enum frontend_tune_state *tune_state = &state->tune_state;
  983. int ret = 0;
  984. u16 reg, upd_demod_gain_period = 0x8000;
  985. switch (*tune_state) {
  986. case CT_AGC_START:
  987. // set power-up level: interf+analog+AGC
  988. if (state->revision != 0x8090)
  989. dib8000_set_adc_state(state, DIBX000_ADC_ON);
  990. else {
  991. dib8000_set_power_mode(state, DIB8000_POWER_ALL);
  992. reg = dib8000_read_word(state, 1947)&0xff00;
  993. dib8000_write_word(state, 1946,
  994. upd_demod_gain_period & 0xFFFF);
  995. /* bit 14 = enDemodGain */
  996. dib8000_write_word(state, 1947, reg | (1<<14) |
  997. ((upd_demod_gain_period >> 16) & 0xFF));
  998. /* enable adc i & q */
  999. reg = dib8000_read_word(state, 1920);
  1000. dib8000_write_word(state, 1920, (reg | 0x3) &
  1001. (~(1 << 7)));
  1002. }
  1003. if (dib8000_set_agc_config(state, (unsigned char)(BAND_OF_FREQUENCY(fe->dtv_property_cache.frequency / 1000))) != 0) {
  1004. *tune_state = CT_AGC_STOP;
  1005. state->status = FE_STATUS_TUNE_FAILED;
  1006. break;
  1007. }
  1008. ret = 70;
  1009. *tune_state = CT_AGC_STEP_0;
  1010. break;
  1011. case CT_AGC_STEP_0:
  1012. //AGC initialization
  1013. if (state->cfg.agc_control)
  1014. state->cfg.agc_control(fe, 1);
  1015. dib8000_restart_agc(state);
  1016. // wait AGC rough lock time
  1017. ret = 50;
  1018. *tune_state = CT_AGC_STEP_1;
  1019. break;
  1020. case CT_AGC_STEP_1:
  1021. // wait AGC accurate lock time
  1022. ret = 70;
  1023. if (dib8000_update_lna(state))
  1024. // wait only AGC rough lock time
  1025. ret = 50;
  1026. else
  1027. *tune_state = CT_AGC_STEP_2;
  1028. break;
  1029. case CT_AGC_STEP_2:
  1030. dib8000_agc_soft_split(state);
  1031. if (state->cfg.agc_control)
  1032. state->cfg.agc_control(fe, 0);
  1033. *tune_state = CT_AGC_STOP;
  1034. break;
  1035. default:
  1036. ret = dib8000_agc_soft_split(state);
  1037. break;
  1038. }
  1039. return ret;
  1040. }
  1041. static void dib8096p_host_bus_drive(struct dib8000_state *state, u8 drive)
  1042. {
  1043. u16 reg;
  1044. drive &= 0x7;
  1045. /* drive host bus 2, 3, 4 */
  1046. reg = dib8000_read_word(state, 1798) &
  1047. ~(0x7 | (0x7 << 6) | (0x7 << 12));
  1048. reg |= (drive<<12) | (drive<<6) | drive;
  1049. dib8000_write_word(state, 1798, reg);
  1050. /* drive host bus 5,6 */
  1051. reg = dib8000_read_word(state, 1799) & ~((0x7 << 2) | (0x7 << 8));
  1052. reg |= (drive<<8) | (drive<<2);
  1053. dib8000_write_word(state, 1799, reg);
  1054. /* drive host bus 7, 8, 9 */
  1055. reg = dib8000_read_word(state, 1800) &
  1056. ~(0x7 | (0x7 << 6) | (0x7 << 12));
  1057. reg |= (drive<<12) | (drive<<6) | drive;
  1058. dib8000_write_word(state, 1800, reg);
  1059. /* drive host bus 10, 11 */
  1060. reg = dib8000_read_word(state, 1801) & ~((0x7 << 2) | (0x7 << 8));
  1061. reg |= (drive<<8) | (drive<<2);
  1062. dib8000_write_word(state, 1801, reg);
  1063. /* drive host bus 12, 13, 14 */
  1064. reg = dib8000_read_word(state, 1802) &
  1065. ~(0x7 | (0x7 << 6) | (0x7 << 12));
  1066. reg |= (drive<<12) | (drive<<6) | drive;
  1067. dib8000_write_word(state, 1802, reg);
  1068. }
  1069. static u32 dib8096p_calcSyncFreq(u32 P_Kin, u32 P_Kout,
  1070. u32 insertExtSynchro, u32 syncSize)
  1071. {
  1072. u32 quantif = 3;
  1073. u32 nom = (insertExtSynchro * P_Kin+syncSize);
  1074. u32 denom = P_Kout;
  1075. u32 syncFreq = ((nom << quantif) / denom);
  1076. if ((syncFreq & ((1 << quantif) - 1)) != 0)
  1077. syncFreq = (syncFreq >> quantif) + 1;
  1078. else
  1079. syncFreq = (syncFreq >> quantif);
  1080. if (syncFreq != 0)
  1081. syncFreq = syncFreq - 1;
  1082. return syncFreq;
  1083. }
  1084. static void dib8096p_cfg_DibTx(struct dib8000_state *state, u32 P_Kin,
  1085. u32 P_Kout, u32 insertExtSynchro, u32 synchroMode,
  1086. u32 syncWord, u32 syncSize)
  1087. {
  1088. dprintk("Configure DibStream Tx");
  1089. dib8000_write_word(state, 1615, 1);
  1090. dib8000_write_word(state, 1603, P_Kin);
  1091. dib8000_write_word(state, 1605, P_Kout);
  1092. dib8000_write_word(state, 1606, insertExtSynchro);
  1093. dib8000_write_word(state, 1608, synchroMode);
  1094. dib8000_write_word(state, 1609, (syncWord >> 16) & 0xffff);
  1095. dib8000_write_word(state, 1610, syncWord & 0xffff);
  1096. dib8000_write_word(state, 1612, syncSize);
  1097. dib8000_write_word(state, 1615, 0);
  1098. }
  1099. static void dib8096p_cfg_DibRx(struct dib8000_state *state, u32 P_Kin,
  1100. u32 P_Kout, u32 synchroMode, u32 insertExtSynchro,
  1101. u32 syncWord, u32 syncSize, u32 dataOutRate)
  1102. {
  1103. u32 syncFreq;
  1104. dprintk("Configure DibStream Rx synchroMode = %d", synchroMode);
  1105. if ((P_Kin != 0) && (P_Kout != 0)) {
  1106. syncFreq = dib8096p_calcSyncFreq(P_Kin, P_Kout,
  1107. insertExtSynchro, syncSize);
  1108. dib8000_write_word(state, 1542, syncFreq);
  1109. }
  1110. dib8000_write_word(state, 1554, 1);
  1111. dib8000_write_word(state, 1536, P_Kin);
  1112. dib8000_write_word(state, 1537, P_Kout);
  1113. dib8000_write_word(state, 1539, synchroMode);
  1114. dib8000_write_word(state, 1540, (syncWord >> 16) & 0xffff);
  1115. dib8000_write_word(state, 1541, syncWord & 0xffff);
  1116. dib8000_write_word(state, 1543, syncSize);
  1117. dib8000_write_word(state, 1544, dataOutRate);
  1118. dib8000_write_word(state, 1554, 0);
  1119. }
  1120. static void dib8096p_enMpegMux(struct dib8000_state *state, int onoff)
  1121. {
  1122. u16 reg_1287;
  1123. reg_1287 = dib8000_read_word(state, 1287);
  1124. switch (onoff) {
  1125. case 1:
  1126. reg_1287 &= ~(1 << 8);
  1127. break;
  1128. case 0:
  1129. reg_1287 |= (1 << 8);
  1130. break;
  1131. }
  1132. dib8000_write_word(state, 1287, reg_1287);
  1133. }
  1134. static void dib8096p_configMpegMux(struct dib8000_state *state,
  1135. u16 pulseWidth, u16 enSerialMode, u16 enSerialClkDiv2)
  1136. {
  1137. u16 reg_1287;
  1138. dprintk("Enable Mpeg mux");
  1139. dib8096p_enMpegMux(state, 0);
  1140. /* If the input mode is MPEG do not divide the serial clock */
  1141. if ((enSerialMode == 1) && (state->input_mode_mpeg == 1))
  1142. enSerialClkDiv2 = 0;
  1143. reg_1287 = ((pulseWidth & 0x1f) << 3) |
  1144. ((enSerialMode & 0x1) << 2) | (enSerialClkDiv2 & 0x1);
  1145. dib8000_write_word(state, 1287, reg_1287);
  1146. dib8096p_enMpegMux(state, 1);
  1147. }
  1148. static void dib8096p_setDibTxMux(struct dib8000_state *state, int mode)
  1149. {
  1150. u16 reg_1288 = dib8000_read_word(state, 1288) & ~(0x7 << 7);
  1151. switch (mode) {
  1152. case MPEG_ON_DIBTX:
  1153. dprintk("SET MPEG ON DIBSTREAM TX");
  1154. dib8096p_cfg_DibTx(state, 8, 5, 0, 0, 0, 0);
  1155. reg_1288 |= (1 << 9); break;
  1156. case DIV_ON_DIBTX:
  1157. dprintk("SET DIV_OUT ON DIBSTREAM TX");
  1158. dib8096p_cfg_DibTx(state, 5, 5, 0, 0, 0, 0);
  1159. reg_1288 |= (1 << 8); break;
  1160. case ADC_ON_DIBTX:
  1161. dprintk("SET ADC_OUT ON DIBSTREAM TX");
  1162. dib8096p_cfg_DibTx(state, 20, 5, 10, 0, 0, 0);
  1163. reg_1288 |= (1 << 7); break;
  1164. default:
  1165. break;
  1166. }
  1167. dib8000_write_word(state, 1288, reg_1288);
  1168. }
  1169. static void dib8096p_setHostBusMux(struct dib8000_state *state, int mode)
  1170. {
  1171. u16 reg_1288 = dib8000_read_word(state, 1288) & ~(0x7 << 4);
  1172. switch (mode) {
  1173. case DEMOUT_ON_HOSTBUS:
  1174. dprintk("SET DEM OUT OLD INTERF ON HOST BUS");
  1175. dib8096p_enMpegMux(state, 0);
  1176. reg_1288 |= (1 << 6);
  1177. break;
  1178. case DIBTX_ON_HOSTBUS:
  1179. dprintk("SET DIBSTREAM TX ON HOST BUS");
  1180. dib8096p_enMpegMux(state, 0);
  1181. reg_1288 |= (1 << 5);
  1182. break;
  1183. case MPEG_ON_HOSTBUS:
  1184. dprintk("SET MPEG MUX ON HOST BUS");
  1185. reg_1288 |= (1 << 4);
  1186. break;
  1187. default:
  1188. break;
  1189. }
  1190. dib8000_write_word(state, 1288, reg_1288);
  1191. }
  1192. static int dib8096p_set_diversity_in(struct dvb_frontend *fe, int onoff)
  1193. {
  1194. struct dib8000_state *state = fe->demodulator_priv;
  1195. u16 reg_1287;
  1196. switch (onoff) {
  1197. case 0: /* only use the internal way - not the diversity input */
  1198. dprintk("%s mode OFF : by default Enable Mpeg INPUT",
  1199. __func__);
  1200. /* outputRate = 8 */
  1201. dib8096p_cfg_DibRx(state, 8, 5, 0, 0, 0, 8, 0);
  1202. /* Do not divide the serial clock of MPEG MUX in
  1203. SERIAL MODE in case input mode MPEG is used */
  1204. reg_1287 = dib8000_read_word(state, 1287);
  1205. /* enSerialClkDiv2 == 1 ? */
  1206. if ((reg_1287 & 0x1) == 1) {
  1207. /* force enSerialClkDiv2 = 0 */
  1208. reg_1287 &= ~0x1;
  1209. dib8000_write_word(state, 1287, reg_1287);
  1210. }
  1211. state->input_mode_mpeg = 1;
  1212. break;
  1213. case 1: /* both ways */
  1214. case 2: /* only the diversity input */
  1215. dprintk("%s ON : Enable diversity INPUT", __func__);
  1216. dib8096p_cfg_DibRx(state, 5, 5, 0, 0, 0, 0, 0);
  1217. state->input_mode_mpeg = 0;
  1218. break;
  1219. }
  1220. dib8000_set_diversity_in(state->fe[0], onoff);
  1221. return 0;
  1222. }
  1223. static int dib8096p_set_output_mode(struct dvb_frontend *fe, int mode)
  1224. {
  1225. struct dib8000_state *state = fe->demodulator_priv;
  1226. u16 outreg, smo_mode, fifo_threshold;
  1227. u8 prefer_mpeg_mux_use = 1;
  1228. int ret = 0;
  1229. state->output_mode = mode;
  1230. dib8096p_host_bus_drive(state, 1);
  1231. fifo_threshold = 1792;
  1232. smo_mode = (dib8000_read_word(state, 299) & 0x0050) | (1 << 1);
  1233. outreg = dib8000_read_word(state, 1286) &
  1234. ~((1 << 10) | (0x7 << 6) | (1 << 1));
  1235. switch (mode) {
  1236. case OUTMODE_HIGH_Z:
  1237. outreg = 0;
  1238. break;
  1239. case OUTMODE_MPEG2_SERIAL:
  1240. if (prefer_mpeg_mux_use) {
  1241. dprintk("dib8096P setting output mode TS_SERIAL using Mpeg Mux");
  1242. dib8096p_configMpegMux(state, 3, 1, 1);
  1243. dib8096p_setHostBusMux(state, MPEG_ON_HOSTBUS);
  1244. } else {/* Use Smooth block */
  1245. dprintk("dib8096P setting output mode TS_SERIAL using Smooth bloc");
  1246. dib8096p_setHostBusMux(state,
  1247. DEMOUT_ON_HOSTBUS);
  1248. outreg |= (2 << 6) | (0 << 1);
  1249. }
  1250. break;
  1251. case OUTMODE_MPEG2_PAR_GATED_CLK:
  1252. if (prefer_mpeg_mux_use) {
  1253. dprintk("dib8096P setting output mode TS_PARALLEL_GATED using Mpeg Mux");
  1254. dib8096p_configMpegMux(state, 2, 0, 0);
  1255. dib8096p_setHostBusMux(state, MPEG_ON_HOSTBUS);
  1256. } else { /* Use Smooth block */
  1257. dprintk("dib8096P setting output mode TS_PARALLEL_GATED using Smooth block");
  1258. dib8096p_setHostBusMux(state,
  1259. DEMOUT_ON_HOSTBUS);
  1260. outreg |= (0 << 6);
  1261. }
  1262. break;
  1263. case OUTMODE_MPEG2_PAR_CONT_CLK: /* Using Smooth block only */
  1264. dprintk("dib8096P setting output mode TS_PARALLEL_CONT using Smooth block");
  1265. dib8096p_setHostBusMux(state, DEMOUT_ON_HOSTBUS);
  1266. outreg |= (1 << 6);
  1267. break;
  1268. case OUTMODE_MPEG2_FIFO:
  1269. /* Using Smooth block because not supported
  1270. by new Mpeg Mux bloc */
  1271. dprintk("dib8096P setting output mode TS_FIFO using Smooth block");
  1272. dib8096p_setHostBusMux(state, DEMOUT_ON_HOSTBUS);
  1273. outreg |= (5 << 6);
  1274. smo_mode |= (3 << 1);
  1275. fifo_threshold = 512;
  1276. break;
  1277. case OUTMODE_DIVERSITY:
  1278. dprintk("dib8096P setting output mode MODE_DIVERSITY");
  1279. dib8096p_setDibTxMux(state, DIV_ON_DIBTX);
  1280. dib8096p_setHostBusMux(state, DIBTX_ON_HOSTBUS);
  1281. break;
  1282. case OUTMODE_ANALOG_ADC:
  1283. dprintk("dib8096P setting output mode MODE_ANALOG_ADC");
  1284. dib8096p_setDibTxMux(state, ADC_ON_DIBTX);
  1285. dib8096p_setHostBusMux(state, DIBTX_ON_HOSTBUS);
  1286. break;
  1287. }
  1288. if (mode != OUTMODE_HIGH_Z)
  1289. outreg |= (1<<10);
  1290. dprintk("output_mpeg2_in_188_bytes = %d",
  1291. state->cfg.output_mpeg2_in_188_bytes);
  1292. if (state->cfg.output_mpeg2_in_188_bytes)
  1293. smo_mode |= (1 << 5);
  1294. ret |= dib8000_write_word(state, 299, smo_mode);
  1295. /* synchronous fread */
  1296. ret |= dib8000_write_word(state, 299 + 1, fifo_threshold);
  1297. ret |= dib8000_write_word(state, 1286, outreg);
  1298. return ret;
  1299. }
  1300. static int map_addr_to_serpar_number(struct i2c_msg *msg)
  1301. {
  1302. if (msg->buf[0] <= 15)
  1303. msg->buf[0] -= 1;
  1304. else if (msg->buf[0] == 17)
  1305. msg->buf[0] = 15;
  1306. else if (msg->buf[0] == 16)
  1307. msg->buf[0] = 17;
  1308. else if (msg->buf[0] == 19)
  1309. msg->buf[0] = 16;
  1310. else if (msg->buf[0] >= 21 && msg->buf[0] <= 25)
  1311. msg->buf[0] -= 3;
  1312. else if (msg->buf[0] == 28)
  1313. msg->buf[0] = 23;
  1314. else if (msg->buf[0] == 99)
  1315. msg->buf[0] = 99;
  1316. else
  1317. return -EINVAL;
  1318. return 0;
  1319. }
  1320. static int dib8096p_tuner_write_serpar(struct i2c_adapter *i2c_adap,
  1321. struct i2c_msg msg[], int num)
  1322. {
  1323. struct dib8000_state *state = i2c_get_adapdata(i2c_adap);
  1324. u8 n_overflow = 1;
  1325. u16 i = 1000;
  1326. u16 serpar_num = msg[0].buf[0];
  1327. while (n_overflow == 1 && i) {
  1328. n_overflow = (dib8000_read_word(state, 1984) >> 1) & 0x1;
  1329. i--;
  1330. if (i == 0)
  1331. dprintk("Tuner ITF: write busy (overflow)");
  1332. }
  1333. dib8000_write_word(state, 1985, (1 << 6) | (serpar_num & 0x3f));
  1334. dib8000_write_word(state, 1986, (msg[0].buf[1] << 8) | msg[0].buf[2]);
  1335. return num;
  1336. }
  1337. static int dib8096p_tuner_read_serpar(struct i2c_adapter *i2c_adap,
  1338. struct i2c_msg msg[], int num)
  1339. {
  1340. struct dib8000_state *state = i2c_get_adapdata(i2c_adap);
  1341. u8 n_overflow = 1, n_empty = 1;
  1342. u16 i = 1000;
  1343. u16 serpar_num = msg[0].buf[0];
  1344. u16 read_word;
  1345. while (n_overflow == 1 && i) {
  1346. n_overflow = (dib8000_read_word(state, 1984) >> 1) & 0x1;
  1347. i--;
  1348. if (i == 0)
  1349. dprintk("TunerITF: read busy (overflow)");
  1350. }
  1351. dib8000_write_word(state, 1985, (0<<6) | (serpar_num&0x3f));
  1352. i = 1000;
  1353. while (n_empty == 1 && i) {
  1354. n_empty = dib8000_read_word(state, 1984)&0x1;
  1355. i--;
  1356. if (i == 0)
  1357. dprintk("TunerITF: read busy (empty)");
  1358. }
  1359. read_word = dib8000_read_word(state, 1987);
  1360. msg[1].buf[0] = (read_word >> 8) & 0xff;
  1361. msg[1].buf[1] = (read_word) & 0xff;
  1362. return num;
  1363. }
  1364. static int dib8096p_tuner_rw_serpar(struct i2c_adapter *i2c_adap,
  1365. struct i2c_msg msg[], int num)
  1366. {
  1367. if (map_addr_to_serpar_number(&msg[0]) == 0) {
  1368. if (num == 1) /* write */
  1369. return dib8096p_tuner_write_serpar(i2c_adap, msg, 1);
  1370. else /* read */
  1371. return dib8096p_tuner_read_serpar(i2c_adap, msg, 2);
  1372. }
  1373. return num;
  1374. }
  1375. static int dib8096p_rw_on_apb(struct i2c_adapter *i2c_adap,
  1376. struct i2c_msg msg[], int num, u16 apb_address)
  1377. {
  1378. struct dib8000_state *state = i2c_get_adapdata(i2c_adap);
  1379. u16 word;
  1380. if (num == 1) { /* write */
  1381. dib8000_write_word(state, apb_address,
  1382. ((msg[0].buf[1] << 8) | (msg[0].buf[2])));
  1383. } else {
  1384. word = dib8000_read_word(state, apb_address);
  1385. msg[1].buf[0] = (word >> 8) & 0xff;
  1386. msg[1].buf[1] = (word) & 0xff;
  1387. }
  1388. return num;
  1389. }
  1390. static int dib8096p_tuner_xfer(struct i2c_adapter *i2c_adap,
  1391. struct i2c_msg msg[], int num)
  1392. {
  1393. struct dib8000_state *state = i2c_get_adapdata(i2c_adap);
  1394. u16 apb_address = 0, word;
  1395. int i = 0;
  1396. switch (msg[0].buf[0]) {
  1397. case 0x12:
  1398. apb_address = 1920;
  1399. break;
  1400. case 0x14:
  1401. apb_address = 1921;
  1402. break;
  1403. case 0x24:
  1404. apb_address = 1922;
  1405. break;
  1406. case 0x1a:
  1407. apb_address = 1923;
  1408. break;
  1409. case 0x22:
  1410. apb_address = 1924;
  1411. break;
  1412. case 0x33:
  1413. apb_address = 1926;
  1414. break;
  1415. case 0x34:
  1416. apb_address = 1927;
  1417. break;
  1418. case 0x35:
  1419. apb_address = 1928;
  1420. break;
  1421. case 0x36:
  1422. apb_address = 1929;
  1423. break;
  1424. case 0x37:
  1425. apb_address = 1930;
  1426. break;
  1427. case 0x38:
  1428. apb_address = 1931;
  1429. break;
  1430. case 0x39:
  1431. apb_address = 1932;
  1432. break;
  1433. case 0x2a:
  1434. apb_address = 1935;
  1435. break;
  1436. case 0x2b:
  1437. apb_address = 1936;
  1438. break;
  1439. case 0x2c:
  1440. apb_address = 1937;
  1441. break;
  1442. case 0x2d:
  1443. apb_address = 1938;
  1444. break;
  1445. case 0x2e:
  1446. apb_address = 1939;
  1447. break;
  1448. case 0x2f:
  1449. apb_address = 1940;
  1450. break;
  1451. case 0x30:
  1452. apb_address = 1941;
  1453. break;
  1454. case 0x31:
  1455. apb_address = 1942;
  1456. break;
  1457. case 0x32:
  1458. apb_address = 1943;
  1459. break;
  1460. case 0x3e:
  1461. apb_address = 1944;
  1462. break;
  1463. case 0x3f:
  1464. apb_address = 1945;
  1465. break;
  1466. case 0x40:
  1467. apb_address = 1948;
  1468. break;
  1469. case 0x25:
  1470. apb_address = 936;
  1471. break;
  1472. case 0x26:
  1473. apb_address = 937;
  1474. break;
  1475. case 0x27:
  1476. apb_address = 938;
  1477. break;
  1478. case 0x28:
  1479. apb_address = 939;
  1480. break;
  1481. case 0x1d:
  1482. /* get sad sel request */
  1483. i = ((dib8000_read_word(state, 921) >> 12)&0x3);
  1484. word = dib8000_read_word(state, 924+i);
  1485. msg[1].buf[0] = (word >> 8) & 0xff;
  1486. msg[1].buf[1] = (word) & 0xff;
  1487. return num;
  1488. case 0x1f:
  1489. if (num == 1) { /* write */
  1490. word = (u16) ((msg[0].buf[1] << 8) |
  1491. msg[0].buf[2]);
  1492. /* in the VGAMODE Sel are located on bit 0/1 */
  1493. word &= 0x3;
  1494. word = (dib8000_read_word(state, 921) &
  1495. ~(3<<12)) | (word<<12);
  1496. /* Set the proper input */
  1497. dib8000_write_word(state, 921, word);
  1498. return num;
  1499. }
  1500. }
  1501. if (apb_address != 0) /* R/W acces via APB */
  1502. return dib8096p_rw_on_apb(i2c_adap, msg, num, apb_address);
  1503. else /* R/W access via SERPAR */
  1504. return dib8096p_tuner_rw_serpar(i2c_adap, msg, num);
  1505. return 0;
  1506. }
  1507. static u32 dib8096p_i2c_func(struct i2c_adapter *adapter)
  1508. {
  1509. return I2C_FUNC_I2C;
  1510. }
  1511. static struct i2c_algorithm dib8096p_tuner_xfer_algo = {
  1512. .master_xfer = dib8096p_tuner_xfer,
  1513. .functionality = dib8096p_i2c_func,
  1514. };
  1515. struct i2c_adapter *dib8096p_get_i2c_tuner(struct dvb_frontend *fe)
  1516. {
  1517. struct dib8000_state *st = fe->demodulator_priv;
  1518. return &st->dib8096p_tuner_adap;
  1519. }
  1520. EXPORT_SYMBOL(dib8096p_get_i2c_tuner);
  1521. int dib8096p_tuner_sleep(struct dvb_frontend *fe, int onoff)
  1522. {
  1523. struct dib8000_state *state = fe->demodulator_priv;
  1524. u16 en_cur_state;
  1525. dprintk("sleep dib8096p: %d", onoff);
  1526. en_cur_state = dib8000_read_word(state, 1922);
  1527. /* LNAs and MIX are ON and therefore it is a valid configuration */
  1528. if (en_cur_state > 0xff)
  1529. state->tuner_enable = en_cur_state ;
  1530. if (onoff)
  1531. en_cur_state &= 0x00ff;
  1532. else {
  1533. if (state->tuner_enable != 0)
  1534. en_cur_state = state->tuner_enable;
  1535. }
  1536. dib8000_write_word(state, 1922, en_cur_state);
  1537. return 0;
  1538. }
  1539. EXPORT_SYMBOL(dib8096p_tuner_sleep);
  1540. static const s32 lut_1000ln_mant[] =
  1541. {
  1542. 908, 7003, 7090, 7170, 7244, 7313, 7377, 7438, 7495, 7549, 7600
  1543. };
  1544. s32 dib8000_get_adc_power(struct dvb_frontend *fe, u8 mode)
  1545. {
  1546. struct dib8000_state *state = fe->demodulator_priv;
  1547. u32 ix = 0, tmp_val = 0, exp = 0, mant = 0;
  1548. s32 val;
  1549. val = dib8000_read32(state, 384);
  1550. if (mode) {
  1551. tmp_val = val;
  1552. while (tmp_val >>= 1)
  1553. exp++;
  1554. mant = (val * 1000 / (1<<exp));
  1555. ix = (u8)((mant-1000)/100); /* index of the LUT */
  1556. val = (lut_1000ln_mant[ix] + 693*(exp-20) - 6908);
  1557. val = (val*256)/1000;
  1558. }
  1559. return val;
  1560. }
  1561. EXPORT_SYMBOL(dib8000_get_adc_power);
  1562. int dib8090p_get_dc_power(struct dvb_frontend *fe, u8 IQ)
  1563. {
  1564. struct dib8000_state *state = fe->demodulator_priv;
  1565. int val = 0;
  1566. switch (IQ) {
  1567. case 1:
  1568. val = dib8000_read_word(state, 403);
  1569. break;
  1570. case 0:
  1571. val = dib8000_read_word(state, 404);
  1572. break;
  1573. }
  1574. if (val & 0x200)
  1575. val -= 1024;
  1576. return val;
  1577. }
  1578. EXPORT_SYMBOL(dib8090p_get_dc_power);
  1579. static void dib8000_update_timf(struct dib8000_state *state)
  1580. {
  1581. u32 timf = state->timf = dib8000_read32(state, 435);
  1582. dib8000_write_word(state, 29, (u16) (timf >> 16));
  1583. dib8000_write_word(state, 30, (u16) (timf & 0xffff));
  1584. dprintk("Updated timing frequency: %d (default: %d)", state->timf, state->timf_default);
  1585. }
  1586. u32 dib8000_ctrl_timf(struct dvb_frontend *fe, uint8_t op, uint32_t timf)
  1587. {
  1588. struct dib8000_state *state = fe->demodulator_priv;
  1589. switch (op) {
  1590. case DEMOD_TIMF_SET:
  1591. state->timf = timf;
  1592. break;
  1593. case DEMOD_TIMF_UPDATE:
  1594. dib8000_update_timf(state);
  1595. break;
  1596. case DEMOD_TIMF_GET:
  1597. break;
  1598. }
  1599. dib8000_set_bandwidth(state->fe[0], 6000);
  1600. return state->timf;
  1601. }
  1602. EXPORT_SYMBOL(dib8000_ctrl_timf);
  1603. static const u16 adc_target_16dB[11] = {
  1604. (1 << 13) - 825 - 117,
  1605. (1 << 13) - 837 - 117,
  1606. (1 << 13) - 811 - 117,
  1607. (1 << 13) - 766 - 117,
  1608. (1 << 13) - 737 - 117,
  1609. (1 << 13) - 693 - 117,
  1610. (1 << 13) - 648 - 117,
  1611. (1 << 13) - 619 - 117,
  1612. (1 << 13) - 575 - 117,
  1613. (1 << 13) - 531 - 117,
  1614. (1 << 13) - 501 - 117
  1615. };
  1616. static const u8 permu_seg[] = { 6, 5, 7, 4, 8, 3, 9, 2, 10, 1, 11, 0, 12 };
  1617. static u16 dib8000_set_layer(struct dib8000_state *state, u8 layer_index, u16 max_constellation)
  1618. {
  1619. u8 cr, constellation, time_intlv;
  1620. struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
  1621. switch (c->layer[layer_index].modulation) {
  1622. case DQPSK:
  1623. constellation = 0;
  1624. break;
  1625. case QPSK:
  1626. constellation = 1;
  1627. break;
  1628. case QAM_16:
  1629. constellation = 2;
  1630. break;
  1631. case QAM_64:
  1632. default:
  1633. constellation = 3;
  1634. break;
  1635. }
  1636. switch (c->layer[layer_index].fec) {
  1637. case FEC_1_2:
  1638. cr = 1;
  1639. break;
  1640. case FEC_2_3:
  1641. cr = 2;
  1642. break;
  1643. case FEC_3_4:
  1644. cr = 3;
  1645. break;
  1646. case FEC_5_6:
  1647. cr = 5;
  1648. break;
  1649. case FEC_7_8:
  1650. default:
  1651. cr = 7;
  1652. break;
  1653. }
  1654. if ((c->layer[layer_index].interleaving > 0) && ((c->layer[layer_index].interleaving <= 3) || (c->layer[layer_index].interleaving == 4 && c->isdbt_sb_mode == 1)))
  1655. time_intlv = c->layer[layer_index].interleaving;
  1656. else
  1657. time_intlv = 0;
  1658. dib8000_write_word(state, 2 + layer_index, (constellation << 10) | ((c->layer[layer_index].segment_count & 0xf) << 6) | (cr << 3) | time_intlv);
  1659. if (c->layer[layer_index].segment_count > 0) {
  1660. switch (max_constellation) {
  1661. case DQPSK:
  1662. case QPSK:
  1663. if (c->layer[layer_index].modulation == QAM_16 || c->layer[layer_index].modulation == QAM_64)
  1664. max_constellation = c->layer[layer_index].modulation;
  1665. break;
  1666. case QAM_16:
  1667. if (c->layer[layer_index].modulation == QAM_64)
  1668. max_constellation = c->layer[layer_index].modulation;
  1669. break;
  1670. }
  1671. }
  1672. return max_constellation;
  1673. }
  1674. static const u16 adp_Q64[4] = {0x0148, 0xfff0, 0x00a4, 0xfff8}; /* P_adp_regul_cnt 0.04, P_adp_noise_cnt -0.002, P_adp_regul_ext 0.02, P_adp_noise_ext -0.001 */
  1675. static const u16 adp_Q16[4] = {0x023d, 0xffdf, 0x00a4, 0xfff0}; /* P_adp_regul_cnt 0.07, P_adp_noise_cnt -0.004, P_adp_regul_ext 0.02, P_adp_noise_ext -0.002 */
  1676. static const u16 adp_Qdefault[4] = {0x099a, 0xffae, 0x0333, 0xfff8}; /* P_adp_regul_cnt 0.3, P_adp_noise_cnt -0.01, P_adp_regul_ext 0.1, P_adp_noise_ext -0.002 */
  1677. static u16 dib8000_adp_fine_tune(struct dib8000_state *state, u16 max_constellation)
  1678. {
  1679. u16 i, ana_gain = 0;
  1680. const u16 *adp;
  1681. /* channel estimation fine configuration */
  1682. switch (max_constellation) {
  1683. case QAM_64:
  1684. ana_gain = 0x7;
  1685. adp = &adp_Q64[0];
  1686. break;
  1687. case QAM_16:
  1688. ana_gain = 0x7;
  1689. adp = &adp_Q16[0];
  1690. break;
  1691. default:
  1692. ana_gain = 0;
  1693. adp = &adp_Qdefault[0];
  1694. break;
  1695. }
  1696. for (i = 0; i < 4; i++)
  1697. dib8000_write_word(state, 215 + i, adp[i]);
  1698. return ana_gain;
  1699. }
  1700. static void dib8000_update_ana_gain(struct dib8000_state *state, u16 ana_gain)
  1701. {
  1702. u16 i;
  1703. dib8000_write_word(state, 116, ana_gain);
  1704. /* update ADC target depending on ana_gain */
  1705. if (ana_gain) { /* set -16dB ADC target for ana_gain=-1 */
  1706. for (i = 0; i < 10; i++)
  1707. dib8000_write_word(state, 80 + i, adc_target_16dB[i]);
  1708. } else { /* set -22dB ADC target for ana_gain=0 */
  1709. for (i = 0; i < 10; i++)
  1710. dib8000_write_word(state, 80 + i, adc_target_16dB[i] - 355);
  1711. }
  1712. }
  1713. static void dib8000_load_ana_fe_coefs(struct dib8000_state *state, const s16 *ana_fe)
  1714. {
  1715. u16 mode = 0;
  1716. if (state->isdbt_cfg_loaded == 0)
  1717. for (mode = 0; mode < 24; mode++)
  1718. dib8000_write_word(state, 117 + mode, ana_fe[mode]);
  1719. }
  1720. static const u16 lut_prbs_2k[14] = {
  1721. 0, 0x423, 0x009, 0x5C7, 0x7A6, 0x3D8, 0x527, 0x7FF, 0x79B, 0x3D6, 0x3A2, 0x53B, 0x2F4, 0x213
  1722. };
  1723. static const u16 lut_prbs_4k[14] = {
  1724. 0, 0x208, 0x0C3, 0x7B9, 0x423, 0x5C7, 0x3D8, 0x7FF, 0x3D6, 0x53B, 0x213, 0x029, 0x0D0, 0x48E
  1725. };
  1726. static const u16 lut_prbs_8k[14] = {
  1727. 0, 0x740, 0x069, 0x7DD, 0x208, 0x7B9, 0x5C7, 0x7FF, 0x53B, 0x029, 0x48E, 0x4C4, 0x367, 0x684
  1728. };
  1729. static u16 dib8000_get_init_prbs(struct dib8000_state *state, u16 subchannel)
  1730. {
  1731. int sub_channel_prbs_group = 0;
  1732. sub_channel_prbs_group = (subchannel / 3) + 1;
  1733. dprintk("sub_channel_prbs_group = %d , subchannel =%d prbs = 0x%04x", sub_channel_prbs_group, subchannel, lut_prbs_8k[sub_channel_prbs_group]);
  1734. switch (state->fe[0]->dtv_property_cache.transmission_mode) {
  1735. case TRANSMISSION_MODE_2K:
  1736. return lut_prbs_2k[sub_channel_prbs_group];
  1737. case TRANSMISSION_MODE_4K:
  1738. return lut_prbs_4k[sub_channel_prbs_group];
  1739. default:
  1740. case TRANSMISSION_MODE_8K:
  1741. return lut_prbs_8k[sub_channel_prbs_group];
  1742. }
  1743. }
  1744. static void dib8000_set_13seg_channel(struct dib8000_state *state)
  1745. {
  1746. u16 i;
  1747. u16 coff_pow = 0x2800;
  1748. state->seg_mask = 0x1fff; /* All 13 segments enabled */
  1749. /* ---- COFF ---- Carloff, the most robust --- */
  1750. if (state->isdbt_cfg_loaded == 0) { /* if not Sound Broadcasting mode : put default values for 13 segments */
  1751. dib8000_write_word(state, 180, (16 << 6) | 9);
  1752. dib8000_write_word(state, 187, (4 << 12) | (8 << 5) | 0x2);
  1753. coff_pow = 0x2800;
  1754. for (i = 0; i < 6; i++)
  1755. dib8000_write_word(state, 181+i, coff_pow);
  1756. /* P_ctrl_corm_thres4pre_freq_inh=1, P_ctrl_pre_freq_mode_sat=1 */
  1757. /* P_ctrl_pre_freq_mode_sat=1, P_ctrl_pre_freq_inh=0, P_ctrl_pre_freq_step = 3, P_pre_freq_win_len=1 */
  1758. dib8000_write_word(state, 338, (1 << 12) | (1 << 10) | (0 << 9) | (3 << 5) | 1);
  1759. /* P_ctrl_pre_freq_win_len=8, P_ctrl_pre_freq_thres_lockin=6 */
  1760. dib8000_write_word(state, 340, (8 << 6) | (6 << 0));
  1761. /* P_ctrl_pre_freq_thres_lockout=4, P_small_use_tmcc/ac/cp=1 */
  1762. dib8000_write_word(state, 341, (4 << 3) | (1 << 2) | (1 << 1) | (1 << 0));
  1763. dib8000_write_word(state, 228, 0); /* default value */
  1764. dib8000_write_word(state, 265, 31); /* default value */
  1765. dib8000_write_word(state, 205, 0x200f); /* init value */
  1766. }
  1767. /*
  1768. * make the cpil_coff_lock more robust but slower p_coff_winlen
  1769. * 6bits; p_coff_thres_lock 6bits (for coff lock if needed)
  1770. */
  1771. if (state->cfg.pll->ifreq == 0)
  1772. dib8000_write_word(state, 266, ~state->seg_mask | state->seg_diff_mask | 0x40); /* P_equal_noise_seg_inh */
  1773. dib8000_load_ana_fe_coefs(state, ana_fe_coeff_13seg);
  1774. }
  1775. static void dib8000_set_subchannel_prbs(struct dib8000_state *state, u16 init_prbs)
  1776. {
  1777. u16 reg_1;
  1778. reg_1 = dib8000_read_word(state, 1);
  1779. dib8000_write_word(state, 1, (init_prbs << 2) | (reg_1 & 0x3)); /* ADDR 1 */
  1780. }
  1781. static void dib8000_small_fine_tune(struct dib8000_state *state)
  1782. {
  1783. u16 i;
  1784. const s16 *ncoeff;
  1785. struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
  1786. dib8000_write_word(state, 352, state->seg_diff_mask);
  1787. dib8000_write_word(state, 353, state->seg_mask);
  1788. /* P_small_coef_ext_enable=ISDB-Tsb, P_small_narrow_band=ISDB-Tsb, P_small_last_seg=13, P_small_offset_num_car=5 */
  1789. dib8000_write_word(state, 351, (c->isdbt_sb_mode << 9) | (c->isdbt_sb_mode << 8) | (13 << 4) | 5);
  1790. if (c->isdbt_sb_mode) {
  1791. /* ---- SMALL ---- */
  1792. switch (c->transmission_mode) {
  1793. case TRANSMISSION_MODE_2K:
  1794. if (c->isdbt_partial_reception == 0) { /* 1-seg */
  1795. if (c->layer[0].modulation == DQPSK) /* DQPSK */
  1796. ncoeff = coeff_2k_sb_1seg_dqpsk;
  1797. else /* QPSK or QAM */
  1798. ncoeff = coeff_2k_sb_1seg;
  1799. } else { /* 3-segments */
  1800. if (c->layer[0].modulation == DQPSK) { /* DQPSK on central segment */
  1801. if (c->layer[1].modulation == DQPSK) /* DQPSK on external segments */
  1802. ncoeff = coeff_2k_sb_3seg_0dqpsk_1dqpsk;
  1803. else /* QPSK or QAM on external segments */
  1804. ncoeff = coeff_2k_sb_3seg_0dqpsk;
  1805. } else { /* QPSK or QAM on central segment */
  1806. if (c->layer[1].modulation == DQPSK) /* DQPSK on external segments */
  1807. ncoeff = coeff_2k_sb_3seg_1dqpsk;
  1808. else /* QPSK or QAM on external segments */
  1809. ncoeff = coeff_2k_sb_3seg;
  1810. }
  1811. }
  1812. break;
  1813. case TRANSMISSION_MODE_4K:
  1814. if (c->isdbt_partial_reception == 0) { /* 1-seg */
  1815. if (c->layer[0].modulation == DQPSK) /* DQPSK */
  1816. ncoeff = coeff_4k_sb_1seg_dqpsk;
  1817. else /* QPSK or QAM */
  1818. ncoeff = coeff_4k_sb_1seg;
  1819. } else { /* 3-segments */
  1820. if (c->layer[0].modulation == DQPSK) { /* DQPSK on central segment */
  1821. if (c->layer[1].modulation == DQPSK) /* DQPSK on external segments */
  1822. ncoeff = coeff_4k_sb_3seg_0dqpsk_1dqpsk;
  1823. else /* QPSK or QAM on external segments */
  1824. ncoeff = coeff_4k_sb_3seg_0dqpsk;
  1825. } else { /* QPSK or QAM on central segment */
  1826. if (c->layer[1].modulation == DQPSK) /* DQPSK on external segments */
  1827. ncoeff = coeff_4k_sb_3seg_1dqpsk;
  1828. else /* QPSK or QAM on external segments */
  1829. ncoeff = coeff_4k_sb_3seg;
  1830. }
  1831. }
  1832. break;
  1833. case TRANSMISSION_MODE_AUTO:
  1834. case TRANSMISSION_MODE_8K:
  1835. default:
  1836. if (c->isdbt_partial_reception == 0) { /* 1-seg */
  1837. if (c->layer[0].modulation == DQPSK) /* DQPSK */
  1838. ncoeff = coeff_8k_sb_1seg_dqpsk;
  1839. else /* QPSK or QAM */
  1840. ncoeff = coeff_8k_sb_1seg;
  1841. } else { /* 3-segments */
  1842. if (c->layer[0].modulation == DQPSK) { /* DQPSK on central segment */
  1843. if (c->layer[1].modulation == DQPSK) /* DQPSK on external segments */
  1844. ncoeff = coeff_8k_sb_3seg_0dqpsk_1dqpsk;
  1845. else /* QPSK or QAM on external segments */
  1846. ncoeff = coeff_8k_sb_3seg_0dqpsk;
  1847. } else { /* QPSK or QAM on central segment */
  1848. if (c->layer[1].modulation == DQPSK) /* DQPSK on external segments */
  1849. ncoeff = coeff_8k_sb_3seg_1dqpsk;
  1850. else /* QPSK or QAM on external segments */
  1851. ncoeff = coeff_8k_sb_3seg;
  1852. }
  1853. }
  1854. break;
  1855. }
  1856. for (i = 0; i < 8; i++)
  1857. dib8000_write_word(state, 343 + i, ncoeff[i]);
  1858. }
  1859. }
  1860. static const u16 coff_thres_1seg[3] = {300, 150, 80};
  1861. static const u16 coff_thres_3seg[3] = {350, 300, 250};
  1862. static void dib8000_set_sb_channel(struct dib8000_state *state)
  1863. {
  1864. struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
  1865. const u16 *coff;
  1866. u16 i;
  1867. if (c->transmission_mode == TRANSMISSION_MODE_2K || c->transmission_mode == TRANSMISSION_MODE_4K) {
  1868. dib8000_write_word(state, 219, dib8000_read_word(state, 219) | 0x1); /* adp_pass =1 */
  1869. dib8000_write_word(state, 190, dib8000_read_word(state, 190) | (0x1 << 14)); /* pha3_force_pha_shift = 1 */
  1870. } else {
  1871. dib8000_write_word(state, 219, dib8000_read_word(state, 219) & 0xfffe); /* adp_pass =0 */
  1872. dib8000_write_word(state, 190, dib8000_read_word(state, 190) & 0xbfff); /* pha3_force_pha_shift = 0 */
  1873. }
  1874. if (c->isdbt_partial_reception == 1) /* 3-segments */
  1875. state->seg_mask = 0x00E0;
  1876. else /* 1-segment */
  1877. state->seg_mask = 0x0040;
  1878. dib8000_write_word(state, 268, (dib8000_read_word(state, 268) & 0xF9FF) | 0x0200);
  1879. /* ---- COFF ---- Carloff, the most robust --- */
  1880. /* P_coff_cpil_alpha=4, P_coff_inh=0, P_coff_cpil_winlen=64, P_coff_narrow_band=1, P_coff_square_val=1, P_coff_one_seg=~partial_rcpt, P_coff_use_tmcc=1, P_coff_use_ac=1 */
  1881. dib8000_write_word(state, 187, (4 << 12) | (0 << 11) | (63 << 5) | (0x3 << 3) | ((~c->isdbt_partial_reception & 1) << 2) | 0x3);
  1882. dib8000_write_word(state, 340, (16 << 6) | (8 << 0)); /* P_ctrl_pre_freq_win_len=16, P_ctrl_pre_freq_thres_lockin=8 */
  1883. dib8000_write_word(state, 341, (6 << 3) | (1 << 2) | (1 << 1) | (1 << 0));/* P_ctrl_pre_freq_thres_lockout=6, P_small_use_tmcc/ac/cp=1 */
  1884. /* Sound Broadcasting mode 1 seg */
  1885. if (c->isdbt_partial_reception == 0) {
  1886. /* P_coff_winlen=63, P_coff_thres_lock=15, P_coff_one_seg_width = (P_mode == 3) , P_coff_one_seg_sym = (P_mode-1) */
  1887. if (state->mode == 3)
  1888. dib8000_write_word(state, 180, 0x1fcf | ((state->mode - 1) << 14));
  1889. else
  1890. dib8000_write_word(state, 180, 0x0fcf | ((state->mode - 1) << 14));
  1891. /* P_ctrl_corm_thres4pre_freq_inh=1,P_ctrl_pre_freq_mode_sat=1, P_ctrl_pre_freq_inh=0, P_ctrl_pre_freq_step = 5, P_pre_freq_win_len=4 */
  1892. dib8000_write_word(state, 338, (1 << 12) | (1 << 10) | (0 << 9) | (5 << 5) | 4);
  1893. coff = &coff_thres_1seg[0];
  1894. } else { /* Sound Broadcasting mode 3 seg */
  1895. dib8000_write_word(state, 180, 0x1fcf | (1 << 14));
  1896. /* P_ctrl_corm_thres4pre_freq_inh = 1, P_ctrl_pre_freq_mode_sat=1, P_ctrl_pre_freq_inh=0, P_ctrl_pre_freq_step = 4, P_pre_freq_win_len=4 */
  1897. dib8000_write_word(state, 338, (1 << 12) | (1 << 10) | (0 << 9) | (4 << 5) | 4);
  1898. coff = &coff_thres_3seg[0];
  1899. }
  1900. dib8000_write_word(state, 228, 1); /* P_2d_mode_byp=1 */
  1901. dib8000_write_word(state, 205, dib8000_read_word(state, 205) & 0xfff0); /* P_cspu_win_cut = 0 */
  1902. if (c->isdbt_partial_reception == 0 && c->transmission_mode == TRANSMISSION_MODE_2K)
  1903. dib8000_write_word(state, 265, 15); /* P_equal_noise_sel = 15 */
  1904. /* Write COFF thres */
  1905. for (i = 0 ; i < 3; i++) {
  1906. dib8000_write_word(state, 181+i, coff[i]);
  1907. dib8000_write_word(state, 184+i, coff[i]);
  1908. }
  1909. /*
  1910. * make the cpil_coff_lock more robust but slower p_coff_winlen
  1911. * 6bits; p_coff_thres_lock 6bits (for coff lock if needed)
  1912. */
  1913. dib8000_write_word(state, 266, ~state->seg_mask | state->seg_diff_mask); /* P_equal_noise_seg_inh */
  1914. if (c->isdbt_partial_reception == 0)
  1915. dib8000_write_word(state, 178, 64); /* P_fft_powrange = 64 */
  1916. else
  1917. dib8000_write_word(state, 178, 32); /* P_fft_powrange = 32 */
  1918. }
  1919. static void dib8000_set_isdbt_common_channel(struct dib8000_state *state, u8 seq, u8 autosearching)
  1920. {
  1921. u16 p_cfr_left_edge = 0, p_cfr_right_edge = 0;
  1922. u16 tmcc_pow = 0, ana_gain = 0, tmp = 0, i = 0, nbseg_diff = 0 ;
  1923. u16 max_constellation = DQPSK;
  1924. int init_prbs;
  1925. struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
  1926. /* P_mode */
  1927. dib8000_write_word(state, 10, (seq << 4));
  1928. /* init mode */
  1929. state->mode = fft_to_mode(state);
  1930. /* set guard */
  1931. tmp = dib8000_read_word(state, 1);
  1932. dib8000_write_word(state, 1, (tmp&0xfffc) | (c->guard_interval & 0x3));
  1933. dib8000_write_word(state, 274, (dib8000_read_word(state, 274) & 0xffcf) | ((c->isdbt_partial_reception & 1) << 5) | ((c->isdbt_sb_mode & 1) << 4));
  1934. /* signal optimization parameter */
  1935. if (c->isdbt_partial_reception) {
  1936. state->seg_diff_mask = (c->layer[0].modulation == DQPSK) << permu_seg[0];
  1937. for (i = 1; i < 3; i++)
  1938. nbseg_diff += (c->layer[i].modulation == DQPSK) * c->layer[i].segment_count;
  1939. for (i = 0; i < nbseg_diff; i++)
  1940. state->seg_diff_mask |= 1 << permu_seg[i+1];
  1941. } else {
  1942. for (i = 0; i < 3; i++)
  1943. nbseg_diff += (c->layer[i].modulation == DQPSK) * c->layer[i].segment_count;
  1944. for (i = 0; i < nbseg_diff; i++)
  1945. state->seg_diff_mask |= 1 << permu_seg[i];
  1946. }
  1947. if (state->seg_diff_mask)
  1948. dib8000_write_word(state, 268, (dib8000_read_word(state, 268) & 0xF9FF) | 0x0200);
  1949. else
  1950. dib8000_write_word(state, 268, (2 << 9) | 39); /*init value */
  1951. for (i = 0; i < 3; i++)
  1952. max_constellation = dib8000_set_layer(state, i, max_constellation);
  1953. if (autosearching == 0) {
  1954. state->layer_b_nb_seg = c->layer[1].segment_count;
  1955. state->layer_c_nb_seg = c->layer[2].segment_count;
  1956. }
  1957. /* WRITE: Mode & Diff mask */
  1958. dib8000_write_word(state, 0, (state->mode << 13) | state->seg_diff_mask);
  1959. state->differential_constellation = (state->seg_diff_mask != 0);
  1960. /* channel estimation fine configuration */
  1961. ana_gain = dib8000_adp_fine_tune(state, max_constellation);
  1962. /* update ana_gain depending on max constellation */
  1963. dib8000_update_ana_gain(state, ana_gain);
  1964. /* ---- ANA_FE ---- */
  1965. if (c->isdbt_partial_reception) /* 3-segments */
  1966. dib8000_load_ana_fe_coefs(state, ana_fe_coeff_3seg);
  1967. else
  1968. dib8000_load_ana_fe_coefs(state, ana_fe_coeff_1seg); /* 1-segment */
  1969. /* TSB or ISDBT ? apply it now */
  1970. if (c->isdbt_sb_mode) {
  1971. dib8000_set_sb_channel(state);
  1972. if (c->isdbt_sb_subchannel < 14)
  1973. init_prbs = dib8000_get_init_prbs(state, c->isdbt_sb_subchannel);
  1974. else
  1975. init_prbs = 0;
  1976. } else {
  1977. dib8000_set_13seg_channel(state);
  1978. init_prbs = 0xfff;
  1979. }
  1980. /* SMALL */
  1981. dib8000_small_fine_tune(state);
  1982. dib8000_set_subchannel_prbs(state, init_prbs);
  1983. /* ---- CHAN_BLK ---- */
  1984. for (i = 0; i < 13; i++) {
  1985. if ((((~state->seg_diff_mask) >> i) & 1) == 1) {
  1986. p_cfr_left_edge += (1 << i) * ((i == 0) || ((((state->seg_mask & (~state->seg_diff_mask)) >> (i - 1)) & 1) == 0));
  1987. p_cfr_right_edge += (1 << i) * ((i == 12) || ((((state->seg_mask & (~state->seg_diff_mask)) >> (i + 1)) & 1) == 0));
  1988. }
  1989. }
  1990. dib8000_write_word(state, 222, p_cfr_left_edge); /* p_cfr_left_edge */
  1991. dib8000_write_word(state, 223, p_cfr_right_edge); /* p_cfr_right_edge */
  1992. /* "P_cspu_left_edge" & "P_cspu_right_edge" not used => do not care */
  1993. dib8000_write_word(state, 189, ~state->seg_mask | state->seg_diff_mask); /* P_lmod4_seg_inh */
  1994. dib8000_write_word(state, 192, ~state->seg_mask | state->seg_diff_mask); /* P_pha3_seg_inh */
  1995. dib8000_write_word(state, 225, ~state->seg_mask | state->seg_diff_mask); /* P_tac_seg_inh */
  1996. if (!autosearching)
  1997. dib8000_write_word(state, 288, (~state->seg_mask | state->seg_diff_mask) & 0x1fff); /* P_tmcc_seg_eq_inh */
  1998. else
  1999. dib8000_write_word(state, 288, 0x1fff); /*disable equalisation of the tmcc when autosearch to be able to find the DQPSK channels. */
  2000. dib8000_write_word(state, 211, state->seg_mask & (~state->seg_diff_mask)); /* P_des_seg_enabled */
  2001. dib8000_write_word(state, 287, ~state->seg_mask | 0x1000); /* P_tmcc_seg_inh */
  2002. dib8000_write_word(state, 178, 32); /* P_fft_powrange = 32 */
  2003. /* ---- TMCC ---- */
  2004. for (i = 0; i < 3; i++)
  2005. tmcc_pow += (((c->layer[i].modulation == DQPSK) * 4 + 1) * c->layer[i].segment_count) ;
  2006. /* Quantif of "P_tmcc_dec_thres_?k" is (0, 5+mode, 9); */
  2007. /* Threshold is set at 1/4 of max power. */
  2008. tmcc_pow *= (1 << (9-2));
  2009. dib8000_write_word(state, 290, tmcc_pow); /* P_tmcc_dec_thres_2k */
  2010. dib8000_write_word(state, 291, tmcc_pow); /* P_tmcc_dec_thres_4k */
  2011. dib8000_write_word(state, 292, tmcc_pow); /* P_tmcc_dec_thres_8k */
  2012. /*dib8000_write_word(state, 287, (1 << 13) | 0x1000 ); */
  2013. /* ---- PHA3 ---- */
  2014. if (state->isdbt_cfg_loaded == 0)
  2015. dib8000_write_word(state, 250, 3285); /* p_2d_hspeed_thr0 */
  2016. state->isdbt_cfg_loaded = 0;
  2017. }
  2018. static u32 dib8000_wait_lock(struct dib8000_state *state, u32 internal,
  2019. u32 wait0_ms, u32 wait1_ms, u32 wait2_ms)
  2020. {
  2021. u32 value = 0; /* P_search_end0 wait time */
  2022. u16 reg = 11; /* P_search_end0 start addr */
  2023. for (reg = 11; reg < 16; reg += 2) {
  2024. if (reg == 11) {
  2025. if (state->revision == 0x8090)
  2026. value = internal * wait1_ms;
  2027. else
  2028. value = internal * wait0_ms;
  2029. } else if (reg == 13)
  2030. value = internal * wait1_ms;
  2031. else if (reg == 15)
  2032. value = internal * wait2_ms;
  2033. dib8000_write_word(state, reg, (u16)((value >> 16) & 0xffff));
  2034. dib8000_write_word(state, (reg + 1), (u16)(value & 0xffff));
  2035. }
  2036. return value;
  2037. }
  2038. static int dib8000_autosearch_start(struct dvb_frontend *fe)
  2039. {
  2040. struct dib8000_state *state = fe->demodulator_priv;
  2041. struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
  2042. u8 slist = 0;
  2043. u32 value, internal = state->cfg.pll->internal;
  2044. if (state->revision == 0x8090)
  2045. internal = dib8000_read32(state, 23) / 1000;
  2046. if (state->autosearch_state == AS_SEARCHING_FFT) {
  2047. dib8000_write_word(state, 37, 0x0065); /* P_ctrl_pha_off_max default values */
  2048. dib8000_write_word(state, 116, 0x0000); /* P_ana_gain to 0 */
  2049. dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x1fff) | (0 << 13) | (1 << 15)); /* P_mode = 0, P_restart_search=1 */
  2050. dib8000_write_word(state, 1, (dib8000_read_word(state, 1) & 0xfffc) | 0); /* P_guard = 0 */
  2051. dib8000_write_word(state, 6, 0); /* P_lock0_mask = 0 */
  2052. dib8000_write_word(state, 7, 0); /* P_lock1_mask = 0 */
  2053. dib8000_write_word(state, 8, 0); /* P_lock2_mask = 0 */
  2054. dib8000_write_word(state, 10, (dib8000_read_word(state, 10) & 0x200) | (16 << 4) | (0 << 0)); /* P_search_list=16, P_search_maxtrial=0 */
  2055. if (state->revision == 0x8090)
  2056. value = dib8000_wait_lock(state, internal, 10, 10, 10); /* time in ms configure P_search_end0 P_search_end1 P_search_end2 */
  2057. else
  2058. value = dib8000_wait_lock(state, internal, 20, 20, 20); /* time in ms configure P_search_end0 P_search_end1 P_search_end2 */
  2059. dib8000_write_word(state, 17, 0);
  2060. dib8000_write_word(state, 18, 200); /* P_search_rstst = 200 */
  2061. dib8000_write_word(state, 19, 0);
  2062. dib8000_write_word(state, 20, 400); /* P_search_rstend = 400 */
  2063. dib8000_write_word(state, 21, (value >> 16) & 0xffff); /* P_search_checkst */
  2064. dib8000_write_word(state, 22, value & 0xffff);
  2065. if (state->revision == 0x8090)
  2066. dib8000_write_word(state, 32, (dib8000_read_word(state, 32) & 0xf0ff) | (0 << 8)); /* P_corm_alpha = 0 */
  2067. else
  2068. dib8000_write_word(state, 32, (dib8000_read_word(state, 32) & 0xf0ff) | (9 << 8)); /* P_corm_alpha = 3 */
  2069. dib8000_write_word(state, 355, 2); /* P_search_param_max = 2 */
  2070. /* P_search_param_select = (1 | 1<<4 | 1 << 8) */
  2071. dib8000_write_word(state, 356, 0);
  2072. dib8000_write_word(state, 357, 0x111);
  2073. dib8000_write_word(state, 770, (dib8000_read_word(state, 770) & 0xdfff) | (1 << 13)); /* P_restart_ccg = 1 */
  2074. dib8000_write_word(state, 770, (dib8000_read_word(state, 770) & 0xdfff) | (0 << 13)); /* P_restart_ccg = 0 */
  2075. dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x7ff) | (0 << 15) | (1 << 13)); /* P_restart_search = 0; */
  2076. } else if (state->autosearch_state == AS_SEARCHING_GUARD) {
  2077. c->transmission_mode = TRANSMISSION_MODE_8K;
  2078. c->guard_interval = GUARD_INTERVAL_1_8;
  2079. c->inversion = 0;
  2080. c->layer[0].modulation = QAM_64;
  2081. c->layer[0].fec = FEC_2_3;
  2082. c->layer[0].interleaving = 0;
  2083. c->layer[0].segment_count = 13;
  2084. slist = 16;
  2085. c->transmission_mode = state->found_nfft;
  2086. dib8000_set_isdbt_common_channel(state, slist, 1);
  2087. /* set lock_mask values */
  2088. dib8000_write_word(state, 6, 0x4);
  2089. if (state->revision == 0x8090)
  2090. dib8000_write_word(state, 7, ((1 << 12) | (1 << 11) | (1 << 10)));/* tmcc_dec_lock, tmcc_sync_lock, tmcc_data_lock, tmcc_bch_uncor */
  2091. else
  2092. dib8000_write_word(state, 7, 0x8);
  2093. dib8000_write_word(state, 8, 0x1000);
  2094. /* set lock_mask wait time values */
  2095. if (state->revision == 0x8090)
  2096. dib8000_wait_lock(state, internal, 50, 100, 1000); /* time in ms configure P_search_end0 P_search_end1 P_search_end2 */
  2097. else
  2098. dib8000_wait_lock(state, internal, 50, 200, 1000); /* time in ms configure P_search_end0 P_search_end1 P_search_end2 */
  2099. dib8000_write_word(state, 355, 3); /* P_search_param_max = 3 */
  2100. /* P_search_param_select = 0xf; look for the 4 different guard intervals */
  2101. dib8000_write_word(state, 356, 0);
  2102. dib8000_write_word(state, 357, 0xf);
  2103. value = dib8000_read_word(state, 0);
  2104. dib8000_write_word(state, 0, (u16)((1 << 15) | value));
  2105. dib8000_read_word(state, 1284); /* reset the INT. n_irq_pending */
  2106. dib8000_write_word(state, 0, (u16)value);
  2107. } else {
  2108. c->inversion = 0;
  2109. c->layer[0].modulation = QAM_64;
  2110. c->layer[0].fec = FEC_2_3;
  2111. c->layer[0].interleaving = 0;
  2112. c->layer[0].segment_count = 13;
  2113. if (!c->isdbt_sb_mode)
  2114. c->layer[0].segment_count = 13;
  2115. /* choose the right list, in sb, always do everything */
  2116. if (c->isdbt_sb_mode) {
  2117. slist = 7;
  2118. dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x9fff) | (1 << 13));
  2119. } else {
  2120. if (c->guard_interval == GUARD_INTERVAL_AUTO) {
  2121. if (c->transmission_mode == TRANSMISSION_MODE_AUTO) {
  2122. c->transmission_mode = TRANSMISSION_MODE_8K;
  2123. c->guard_interval = GUARD_INTERVAL_1_8;
  2124. slist = 7;
  2125. dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x9fff) | (1 << 13)); /* P_mode = 1 to have autosearch start ok with mode2 */
  2126. } else {
  2127. c->guard_interval = GUARD_INTERVAL_1_8;
  2128. slist = 3;
  2129. }
  2130. } else {
  2131. if (c->transmission_mode == TRANSMISSION_MODE_AUTO) {
  2132. c->transmission_mode = TRANSMISSION_MODE_8K;
  2133. slist = 2;
  2134. dib8000_write_word(state, 0, (dib8000_read_word(state, 0) & 0x9fff) | (1 << 13)); /* P_mode = 1 */
  2135. } else
  2136. slist = 0;
  2137. }
  2138. }
  2139. dprintk("Using list for autosearch : %d", slist);
  2140. dib8000_set_isdbt_common_channel(state, slist, 1);
  2141. /* set lock_mask values */
  2142. dib8000_write_word(state, 6, 0x4);
  2143. if (state->revision == 0x8090)
  2144. dib8000_write_word(state, 7, (1 << 12) | (1 << 11) | (1 << 10));
  2145. else
  2146. dib8000_write_word(state, 7, 0x8);
  2147. dib8000_write_word(state, 8, 0x1000);
  2148. /* set lock_mask wait time values */
  2149. if (state->revision == 0x8090)
  2150. dib8000_wait_lock(state, internal, 50, 200, 1000); /* time in ms configure P_search_end0 P_search_end1 P_search_end2 */
  2151. else
  2152. dib8000_wait_lock(state, internal, 50, 100, 1000); /* time in ms configure P_search_end0 P_search_end1 P_search_end2 */
  2153. value = dib8000_read_word(state, 0);
  2154. dib8000_write_word(state, 0, (u16)((1 << 15) | value));
  2155. dib8000_read_word(state, 1284); /* reset the INT. n_irq_pending */
  2156. dib8000_write_word(state, 0, (u16)value);
  2157. }
  2158. return 0;
  2159. }
  2160. static int dib8000_autosearch_irq(struct dvb_frontend *fe)
  2161. {
  2162. struct dib8000_state *state = fe->demodulator_priv;
  2163. u16 irq_pending = dib8000_read_word(state, 1284);
  2164. if (state->autosearch_state == AS_SEARCHING_FFT) {
  2165. if (irq_pending & 0x1) {
  2166. dprintk("dib8000_autosearch_irq: max correlation result available");
  2167. return 3;
  2168. }
  2169. } else {
  2170. if (irq_pending & 0x1) { /* failed */
  2171. dprintk("dib8000_autosearch_irq failed");
  2172. return 1;
  2173. }
  2174. if (irq_pending & 0x2) { /* succeeded */
  2175. dprintk("dib8000_autosearch_irq succeeded");
  2176. return 2;
  2177. }
  2178. }
  2179. return 0; // still pending
  2180. }
  2181. static void dib8000_viterbi_state(struct dib8000_state *state, u8 onoff)
  2182. {
  2183. u16 tmp;
  2184. tmp = dib8000_read_word(state, 771);
  2185. if (onoff) /* start P_restart_chd : channel_decoder */
  2186. dib8000_write_word(state, 771, tmp & 0xfffd);
  2187. else /* stop P_restart_chd : channel_decoder */
  2188. dib8000_write_word(state, 771, tmp | (1<<1));
  2189. }
  2190. static void dib8000_set_dds(struct dib8000_state *state, s32 offset_khz)
  2191. {
  2192. s16 unit_khz_dds_val;
  2193. u32 abs_offset_khz = ABS(offset_khz);
  2194. u32 dds = state->cfg.pll->ifreq & 0x1ffffff;
  2195. u8 invert = !!(state->cfg.pll->ifreq & (1 << 25));
  2196. u8 ratio;
  2197. if (state->revision == 0x8090) {
  2198. ratio = 4;
  2199. unit_khz_dds_val = (1<<26) / (dib8000_read32(state, 23) / 1000);
  2200. if (offset_khz < 0)
  2201. dds = (1 << 26) - (abs_offset_khz * unit_khz_dds_val);
  2202. else
  2203. dds = (abs_offset_khz * unit_khz_dds_val);
  2204. if (invert)
  2205. dds = (1<<26) - dds;
  2206. } else {
  2207. ratio = 2;
  2208. unit_khz_dds_val = (u16) (67108864 / state->cfg.pll->internal);
  2209. if (offset_khz < 0)
  2210. unit_khz_dds_val *= -1;
  2211. /* IF tuner */
  2212. if (invert)
  2213. dds -= abs_offset_khz * unit_khz_dds_val;
  2214. else
  2215. dds += abs_offset_khz * unit_khz_dds_val;
  2216. }
  2217. dprintk("setting a DDS frequency offset of %c%dkHz", invert ? '-' : ' ', dds / unit_khz_dds_val);
  2218. if (abs_offset_khz <= (state->cfg.pll->internal / ratio)) {
  2219. /* Max dds offset is the half of the demod freq */
  2220. dib8000_write_word(state, 26, invert);
  2221. dib8000_write_word(state, 27, (u16)(dds >> 16) & 0x1ff);
  2222. dib8000_write_word(state, 28, (u16)(dds & 0xffff));
  2223. }
  2224. }
  2225. static void dib8000_set_frequency_offset(struct dib8000_state *state)
  2226. {
  2227. struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
  2228. int i;
  2229. u32 current_rf;
  2230. int total_dds_offset_khz;
  2231. if (state->fe[0]->ops.tuner_ops.get_frequency)
  2232. state->fe[0]->ops.tuner_ops.get_frequency(state->fe[0], &current_rf);
  2233. else
  2234. current_rf = c->frequency;
  2235. current_rf /= 1000;
  2236. total_dds_offset_khz = (int)current_rf - (int)c->frequency / 1000;
  2237. if (c->isdbt_sb_mode) {
  2238. state->subchannel = c->isdbt_sb_subchannel;
  2239. i = dib8000_read_word(state, 26) & 1; /* P_dds_invspec */
  2240. dib8000_write_word(state, 26, c->inversion ^ i);
  2241. if (state->cfg.pll->ifreq == 0) { /* low if tuner */
  2242. if ((c->inversion ^ i) == 0)
  2243. dib8000_write_word(state, 26, dib8000_read_word(state, 26) | 1);
  2244. } else {
  2245. if ((c->inversion ^ i) == 0)
  2246. total_dds_offset_khz *= -1;
  2247. }
  2248. }
  2249. dprintk("%dkhz tuner offset (frequency = %dHz & current_rf = %dHz) total_dds_offset_hz = %d", c->frequency - current_rf, c->frequency, current_rf, total_dds_offset_khz);
  2250. /* apply dds offset now */
  2251. dib8000_set_dds(state, total_dds_offset_khz);
  2252. }
  2253. static u16 LUT_isdbt_symbol_duration[4] = { 26, 101, 63 };
  2254. static u32 dib8000_get_symbol_duration(struct dib8000_state *state)
  2255. {
  2256. struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
  2257. u16 i;
  2258. switch (c->transmission_mode) {
  2259. case TRANSMISSION_MODE_2K:
  2260. i = 0;
  2261. break;
  2262. case TRANSMISSION_MODE_4K:
  2263. i = 2;
  2264. break;
  2265. default:
  2266. case TRANSMISSION_MODE_AUTO:
  2267. case TRANSMISSION_MODE_8K:
  2268. i = 1;
  2269. break;
  2270. }
  2271. return (LUT_isdbt_symbol_duration[i] / (c->bandwidth_hz / 1000)) + 1;
  2272. }
  2273. static void dib8000_set_isdbt_loop_params(struct dib8000_state *state, enum param_loop_step loop_step)
  2274. {
  2275. struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
  2276. u16 reg_32 = 0, reg_37 = 0;
  2277. switch (loop_step) {
  2278. case LOOP_TUNE_1:
  2279. if (c->isdbt_sb_mode) {
  2280. if (c->isdbt_partial_reception == 0) {
  2281. reg_32 = ((11 - state->mode) << 12) | (6 << 8) | 0x40; /* P_timf_alpha = (11-P_mode), P_corm_alpha=6, P_corm_thres=0x40 */
  2282. reg_37 = (3 << 5) | (0 << 4) | (10 - state->mode); /* P_ctrl_pha_off_max=3 P_ctrl_sfreq_inh =0 P_ctrl_sfreq_step = (10-P_mode) */
  2283. } else { /* Sound Broadcasting mode 3 seg */
  2284. reg_32 = ((10 - state->mode) << 12) | (6 << 8) | 0x60; /* P_timf_alpha = (10-P_mode), P_corm_alpha=6, P_corm_thres=0x60 */
  2285. reg_37 = (3 << 5) | (0 << 4) | (9 - state->mode); /* P_ctrl_pha_off_max=3 P_ctrl_sfreq_inh =0 P_ctrl_sfreq_step = (9-P_mode) */
  2286. }
  2287. } else { /* 13-seg start conf offset loop parameters */
  2288. reg_32 = ((9 - state->mode) << 12) | (6 << 8) | 0x80; /* P_timf_alpha = (9-P_mode, P_corm_alpha=6, P_corm_thres=0x80 */
  2289. reg_37 = (3 << 5) | (0 << 4) | (8 - state->mode); /* P_ctrl_pha_off_max=3 P_ctrl_sfreq_inh =0 P_ctrl_sfreq_step = 9 */
  2290. }
  2291. break;
  2292. case LOOP_TUNE_2:
  2293. if (c->isdbt_sb_mode) {
  2294. if (c->isdbt_partial_reception == 0) { /* Sound Broadcasting mode 1 seg */
  2295. reg_32 = ((13-state->mode) << 12) | (6 << 8) | 0x40; /* P_timf_alpha = (13-P_mode) , P_corm_alpha=6, P_corm_thres=0x40*/
  2296. reg_37 = (12-state->mode) | ((5 + state->mode) << 5);
  2297. } else { /* Sound Broadcasting mode 3 seg */
  2298. reg_32 = ((12-state->mode) << 12) | (6 << 8) | 0x60; /* P_timf_alpha = (12-P_mode) , P_corm_alpha=6, P_corm_thres=0x60 */
  2299. reg_37 = (11-state->mode) | ((5 + state->mode) << 5);
  2300. }
  2301. } else { /* 13 seg */
  2302. reg_32 = ((11-state->mode) << 12) | (6 << 8) | 0x80; /* P_timf_alpha = 8 , P_corm_alpha=6, P_corm_thres=0x80 */
  2303. reg_37 = ((5+state->mode) << 5) | (10 - state->mode);
  2304. }
  2305. break;
  2306. }
  2307. dib8000_write_word(state, 32, reg_32);
  2308. dib8000_write_word(state, 37, reg_37);
  2309. }
  2310. static void dib8000_demod_restart(struct dib8000_state *state)
  2311. {
  2312. dib8000_write_word(state, 770, 0x4000);
  2313. dib8000_write_word(state, 770, 0x0000);
  2314. return;
  2315. }
  2316. static void dib8000_set_sync_wait(struct dib8000_state *state)
  2317. {
  2318. struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
  2319. u16 sync_wait = 64;
  2320. /* P_dvsy_sync_wait - reuse mode */
  2321. switch (c->transmission_mode) {
  2322. case TRANSMISSION_MODE_8K:
  2323. sync_wait = 256;
  2324. break;
  2325. case TRANSMISSION_MODE_4K:
  2326. sync_wait = 128;
  2327. break;
  2328. default:
  2329. case TRANSMISSION_MODE_2K:
  2330. sync_wait = 64;
  2331. break;
  2332. }
  2333. if (state->cfg.diversity_delay == 0)
  2334. sync_wait = (sync_wait * (1 << (c->guard_interval)) * 3) / 2 + 48; /* add 50% SFN margin + compensate for one DVSY-fifo */
  2335. else
  2336. sync_wait = (sync_wait * (1 << (c->guard_interval)) * 3) / 2 + state->cfg.diversity_delay; /* add 50% SFN margin + compensate for DVSY-fifo */
  2337. dib8000_write_word(state, 273, (dib8000_read_word(state, 273) & 0x000f) | (sync_wait << 4));
  2338. }
  2339. static u32 dib8000_get_timeout(struct dib8000_state *state, u32 delay, enum timeout_mode mode)
  2340. {
  2341. if (mode == SYMBOL_DEPENDENT_ON)
  2342. return systime() + (delay * state->symbol_duration);
  2343. else
  2344. return systime() + delay;
  2345. }
  2346. static s32 dib8000_get_status(struct dvb_frontend *fe)
  2347. {
  2348. struct dib8000_state *state = fe->demodulator_priv;
  2349. return state->status;
  2350. }
  2351. enum frontend_tune_state dib8000_get_tune_state(struct dvb_frontend *fe)
  2352. {
  2353. struct dib8000_state *state = fe->demodulator_priv;
  2354. return state->tune_state;
  2355. }
  2356. EXPORT_SYMBOL(dib8000_get_tune_state);
  2357. int dib8000_set_tune_state(struct dvb_frontend *fe, enum frontend_tune_state tune_state)
  2358. {
  2359. struct dib8000_state *state = fe->demodulator_priv;
  2360. state->tune_state = tune_state;
  2361. return 0;
  2362. }
  2363. EXPORT_SYMBOL(dib8000_set_tune_state);
  2364. static int dib8000_tune_restart_from_demod(struct dvb_frontend *fe)
  2365. {
  2366. struct dib8000_state *state = fe->demodulator_priv;
  2367. state->status = FE_STATUS_TUNE_PENDING;
  2368. state->tune_state = CT_DEMOD_START;
  2369. return 0;
  2370. }
  2371. static u16 dib8000_read_lock(struct dvb_frontend *fe)
  2372. {
  2373. struct dib8000_state *state = fe->demodulator_priv;
  2374. if (state->revision == 0x8090)
  2375. return dib8000_read_word(state, 570);
  2376. return dib8000_read_word(state, 568);
  2377. }
  2378. static int dib8090p_init_sdram(struct dib8000_state *state)
  2379. {
  2380. u16 reg = 0;
  2381. dprintk("init sdram");
  2382. reg = dib8000_read_word(state, 274) & 0xfff0;
  2383. dib8000_write_word(state, 274, reg | 0x7); /* P_dintlv_delay_ram = 7 because of MobileSdram */
  2384. dib8000_write_word(state, 1803, (7 << 2));
  2385. reg = dib8000_read_word(state, 1280);
  2386. dib8000_write_word(state, 1280, reg | (1 << 2)); /* force restart P_restart_sdram */
  2387. dib8000_write_word(state, 1280, reg); /* release restart P_restart_sdram */
  2388. return 0;
  2389. }
  2390. static int dib8000_tune(struct dvb_frontend *fe)
  2391. {
  2392. struct dib8000_state *state = fe->demodulator_priv;
  2393. struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
  2394. enum frontend_tune_state *tune_state = &state->tune_state;
  2395. u16 locks, deeper_interleaver = 0, i;
  2396. int ret = 1; /* 1 symbol duration (in 100us unit) delay most of the time */
  2397. u32 *timeout = &state->timeout;
  2398. u32 now = systime();
  2399. #ifdef DIB8000_AGC_FREEZE
  2400. u16 agc1, agc2;
  2401. #endif
  2402. u32 corm[4] = {0, 0, 0, 0};
  2403. u8 find_index, max_value;
  2404. #if 0
  2405. if (*tune_state < CT_DEMOD_STOP)
  2406. dprintk("IN: context status = %d, TUNE_STATE %d autosearch step = %u systime = %u", state->channel_parameters_set, *tune_state, state->autosearch_state, now);
  2407. #endif
  2408. switch (*tune_state) {
  2409. case CT_DEMOD_START: /* 30 */
  2410. if (state->revision == 0x8090)
  2411. dib8090p_init_sdram(state);
  2412. state->status = FE_STATUS_TUNE_PENDING;
  2413. if ((c->delivery_system != SYS_ISDBT) ||
  2414. (c->inversion == INVERSION_AUTO) ||
  2415. (c->transmission_mode == TRANSMISSION_MODE_AUTO) ||
  2416. (c->guard_interval == GUARD_INTERVAL_AUTO) ||
  2417. (((c->isdbt_layer_enabled & (1 << 0)) != 0) &&
  2418. (c->layer[0].segment_count != 0xff) &&
  2419. (c->layer[0].segment_count != 0) &&
  2420. ((c->layer[0].modulation == QAM_AUTO) ||
  2421. (c->layer[0].fec == FEC_AUTO))) ||
  2422. (((c->isdbt_layer_enabled & (1 << 1)) != 0) &&
  2423. (c->layer[1].segment_count != 0xff) &&
  2424. (c->layer[1].segment_count != 0) &&
  2425. ((c->layer[1].modulation == QAM_AUTO) ||
  2426. (c->layer[1].fec == FEC_AUTO))) ||
  2427. (((c->isdbt_layer_enabled & (1 << 2)) != 0) &&
  2428. (c->layer[2].segment_count != 0xff) &&
  2429. (c->layer[2].segment_count != 0) &&
  2430. ((c->layer[2].modulation == QAM_AUTO) ||
  2431. (c->layer[2].fec == FEC_AUTO))) ||
  2432. (((c->layer[0].segment_count == 0) ||
  2433. ((c->isdbt_layer_enabled & (1 << 0)) == 0)) &&
  2434. ((c->layer[1].segment_count == 0) ||
  2435. ((c->isdbt_layer_enabled & (2 << 0)) == 0)) &&
  2436. ((c->layer[2].segment_count == 0) || ((c->isdbt_layer_enabled & (3 << 0)) == 0))))
  2437. state->channel_parameters_set = 0; /* auto search */
  2438. else
  2439. state->channel_parameters_set = 1; /* channel parameters are known */
  2440. dib8000_viterbi_state(state, 0); /* force chan dec in restart */
  2441. /* Layer monit */
  2442. dib8000_write_word(state, 285, dib8000_read_word(state, 285) & 0x60);
  2443. dib8000_set_frequency_offset(state);
  2444. dib8000_set_bandwidth(fe, c->bandwidth_hz / 1000);
  2445. if (state->channel_parameters_set == 0) { /* The channel struct is unknown, search it ! */
  2446. #ifdef DIB8000_AGC_FREEZE
  2447. if (state->revision != 0x8090) {
  2448. state->agc1_max = dib8000_read_word(state, 108);
  2449. state->agc1_min = dib8000_read_word(state, 109);
  2450. state->agc2_max = dib8000_read_word(state, 110);
  2451. state->agc2_min = dib8000_read_word(state, 111);
  2452. agc1 = dib8000_read_word(state, 388);
  2453. agc2 = dib8000_read_word(state, 389);
  2454. dib8000_write_word(state, 108, agc1);
  2455. dib8000_write_word(state, 109, agc1);
  2456. dib8000_write_word(state, 110, agc2);
  2457. dib8000_write_word(state, 111, agc2);
  2458. }
  2459. #endif
  2460. state->autosearch_state = AS_SEARCHING_FFT;
  2461. state->found_nfft = TRANSMISSION_MODE_AUTO;
  2462. state->found_guard = GUARD_INTERVAL_AUTO;
  2463. *tune_state = CT_DEMOD_SEARCH_NEXT;
  2464. } else { /* we already know the channel struct so TUNE only ! */
  2465. state->autosearch_state = AS_DONE;
  2466. *tune_state = CT_DEMOD_STEP_3;
  2467. }
  2468. state->symbol_duration = dib8000_get_symbol_duration(state);
  2469. break;
  2470. case CT_DEMOD_SEARCH_NEXT: /* 51 */
  2471. dib8000_autosearch_start(fe);
  2472. if (state->revision == 0x8090)
  2473. ret = 50;
  2474. else
  2475. ret = 15;
  2476. *tune_state = CT_DEMOD_STEP_1;
  2477. break;
  2478. case CT_DEMOD_STEP_1: /* 31 */
  2479. switch (dib8000_autosearch_irq(fe)) {
  2480. case 1: /* fail */
  2481. state->status = FE_STATUS_TUNE_FAILED;
  2482. state->autosearch_state = AS_DONE;
  2483. *tune_state = CT_DEMOD_STOP; /* else we are done here */
  2484. break;
  2485. case 2: /* Succes */
  2486. state->status = FE_STATUS_FFT_SUCCESS; /* signal to the upper layer, that there was a channel found and the parameters can be read */
  2487. *tune_state = CT_DEMOD_STEP_3;
  2488. if (state->autosearch_state == AS_SEARCHING_GUARD)
  2489. *tune_state = CT_DEMOD_STEP_2;
  2490. else
  2491. state->autosearch_state = AS_DONE;
  2492. break;
  2493. case 3: /* Autosearch FFT max correlation endded */
  2494. *tune_state = CT_DEMOD_STEP_2;
  2495. break;
  2496. }
  2497. break;
  2498. case CT_DEMOD_STEP_2:
  2499. switch (state->autosearch_state) {
  2500. case AS_SEARCHING_FFT:
  2501. /* searching for the correct FFT */
  2502. if (state->revision == 0x8090) {
  2503. corm[2] = (dib8000_read_word(state, 596) << 16) | (dib8000_read_word(state, 597));
  2504. corm[1] = (dib8000_read_word(state, 598) << 16) | (dib8000_read_word(state, 599));
  2505. corm[0] = (dib8000_read_word(state, 600) << 16) | (dib8000_read_word(state, 601));
  2506. } else {
  2507. corm[2] = (dib8000_read_word(state, 594) << 16) | (dib8000_read_word(state, 595));
  2508. corm[1] = (dib8000_read_word(state, 596) << 16) | (dib8000_read_word(state, 597));
  2509. corm[0] = (dib8000_read_word(state, 598) << 16) | (dib8000_read_word(state, 599));
  2510. }
  2511. /* dprintk("corm fft: %u %u %u", corm[0], corm[1], corm[2]); */
  2512. max_value = 0;
  2513. for (find_index = 1 ; find_index < 3 ; find_index++) {
  2514. if (corm[max_value] < corm[find_index])
  2515. max_value = find_index ;
  2516. }
  2517. switch (max_value) {
  2518. case 0:
  2519. state->found_nfft = TRANSMISSION_MODE_2K;
  2520. break;
  2521. case 1:
  2522. state->found_nfft = TRANSMISSION_MODE_4K;
  2523. break;
  2524. case 2:
  2525. default:
  2526. state->found_nfft = TRANSMISSION_MODE_8K;
  2527. break;
  2528. }
  2529. /* dprintk("Autosearch FFT has found Mode %d", max_value + 1); */
  2530. *tune_state = CT_DEMOD_SEARCH_NEXT;
  2531. state->autosearch_state = AS_SEARCHING_GUARD;
  2532. if (state->revision == 0x8090)
  2533. ret = 50;
  2534. else
  2535. ret = 10;
  2536. break;
  2537. case AS_SEARCHING_GUARD:
  2538. /* searching for the correct guard interval */
  2539. if (state->revision == 0x8090)
  2540. state->found_guard = dib8000_read_word(state, 572) & 0x3;
  2541. else
  2542. state->found_guard = dib8000_read_word(state, 570) & 0x3;
  2543. /* dprintk("guard interval found=%i", state->found_guard); */
  2544. *tune_state = CT_DEMOD_STEP_3;
  2545. break;
  2546. default:
  2547. /* the demod should never be in this state */
  2548. state->status = FE_STATUS_TUNE_FAILED;
  2549. state->autosearch_state = AS_DONE;
  2550. *tune_state = CT_DEMOD_STOP; /* else we are done here */
  2551. break;
  2552. }
  2553. break;
  2554. case CT_DEMOD_STEP_3: /* 33 */
  2555. state->symbol_duration = dib8000_get_symbol_duration(state);
  2556. dib8000_set_isdbt_loop_params(state, LOOP_TUNE_1);
  2557. dib8000_set_isdbt_common_channel(state, 0, 0);/* setting the known channel parameters here */
  2558. *tune_state = CT_DEMOD_STEP_4;
  2559. break;
  2560. case CT_DEMOD_STEP_4: /* (34) */
  2561. dib8000_demod_restart(state);
  2562. dib8000_set_sync_wait(state);
  2563. dib8000_set_diversity_in(state->fe[0], state->diversity_onoff);
  2564. locks = (dib8000_read_word(state, 180) >> 6) & 0x3f; /* P_coff_winlen ? */
  2565. /* coff should lock over P_coff_winlen ofdm symbols : give 3 times this lenght to lock */
  2566. *timeout = dib8000_get_timeout(state, 2 * locks, SYMBOL_DEPENDENT_ON);
  2567. *tune_state = CT_DEMOD_STEP_5;
  2568. break;
  2569. case CT_DEMOD_STEP_5: /* (35) */
  2570. locks = dib8000_read_lock(fe);
  2571. if (locks & (0x3 << 11)) { /* coff-lock and off_cpil_lock achieved */
  2572. dib8000_update_timf(state); /* we achieved a coff_cpil_lock - it's time to update the timf */
  2573. if (!state->differential_constellation) {
  2574. /* 2 times lmod4_win_len + 10 symbols (pipe delay after coff + nb to compute a 1st correlation) */
  2575. *timeout = dib8000_get_timeout(state, (20 * ((dib8000_read_word(state, 188)>>5)&0x1f)), SYMBOL_DEPENDENT_ON);
  2576. *tune_state = CT_DEMOD_STEP_7;
  2577. } else {
  2578. *tune_state = CT_DEMOD_STEP_8;
  2579. }
  2580. } else if (now > *timeout) {
  2581. *tune_state = CT_DEMOD_STEP_6; /* goto check for diversity input connection */
  2582. }
  2583. break;
  2584. case CT_DEMOD_STEP_6: /* (36) if there is an input (diversity) */
  2585. if ((state->fe[1] != NULL) && (state->output_mode != OUTMODE_DIVERSITY)) {
  2586. /* if there is a diversity fe in input and this fe is has not already failled : wait here until this this fe has succedeed or failled */
  2587. if (dib8000_get_status(state->fe[1]) <= FE_STATUS_STD_SUCCESS) /* Something is locked on the input fe */
  2588. *tune_state = CT_DEMOD_STEP_8; /* go for mpeg */
  2589. else if (dib8000_get_status(state->fe[1]) >= FE_STATUS_TUNE_TIME_TOO_SHORT) { /* fe in input failled also, break the current one */
  2590. *tune_state = CT_DEMOD_STOP; /* else we are done here ; step 8 will close the loops and exit */
  2591. dib8000_viterbi_state(state, 1); /* start viterbi chandec */
  2592. dib8000_set_isdbt_loop_params(state, LOOP_TUNE_2);
  2593. state->status = FE_STATUS_TUNE_FAILED;
  2594. }
  2595. } else {
  2596. dib8000_viterbi_state(state, 1); /* start viterbi chandec */
  2597. dib8000_set_isdbt_loop_params(state, LOOP_TUNE_2);
  2598. *tune_state = CT_DEMOD_STOP; /* else we are done here ; step 8 will close the loops and exit */
  2599. state->status = FE_STATUS_TUNE_FAILED;
  2600. }
  2601. break;
  2602. case CT_DEMOD_STEP_7: /* 37 */
  2603. locks = dib8000_read_lock(fe);
  2604. if (locks & (1<<10)) { /* lmod4_lock */
  2605. ret = 14; /* wait for 14 symbols */
  2606. *tune_state = CT_DEMOD_STEP_8;
  2607. } else if (now > *timeout)
  2608. *tune_state = CT_DEMOD_STEP_6; /* goto check for diversity input connection */
  2609. break;
  2610. case CT_DEMOD_STEP_8: /* 38 */
  2611. dib8000_viterbi_state(state, 1); /* start viterbi chandec */
  2612. dib8000_set_isdbt_loop_params(state, LOOP_TUNE_2);
  2613. /* mpeg will never lock on this condition because init_prbs is not set : search for it !*/
  2614. if (c->isdbt_sb_mode
  2615. && c->isdbt_sb_subchannel < 14
  2616. && !state->differential_constellation) {
  2617. state->subchannel = 0;
  2618. *tune_state = CT_DEMOD_STEP_11;
  2619. } else {
  2620. *tune_state = CT_DEMOD_STEP_9;
  2621. state->status = FE_STATUS_LOCKED;
  2622. }
  2623. break;
  2624. case CT_DEMOD_STEP_9: /* 39 */
  2625. if ((state->revision == 0x8090) || ((dib8000_read_word(state, 1291) >> 9) & 0x1)) { /* fe capable of deinterleaving : esram */
  2626. /* defines timeout for mpeg lock depending on interleaver lenght of longest layer */
  2627. for (i = 0; i < 3; i++) {
  2628. if (c->layer[i].interleaving >= deeper_interleaver) {
  2629. dprintk("layer%i: time interleaver = %d ", i, c->layer[i].interleaving);
  2630. if (c->layer[i].segment_count > 0) { /* valid layer */
  2631. deeper_interleaver = c->layer[0].interleaving;
  2632. state->longest_intlv_layer = i;
  2633. }
  2634. }
  2635. }
  2636. if (deeper_interleaver == 0)
  2637. locks = 2; /* locks is the tmp local variable name */
  2638. else if (deeper_interleaver == 3)
  2639. locks = 8;
  2640. else
  2641. locks = 2 * deeper_interleaver;
  2642. if (state->diversity_onoff != 0) /* because of diversity sync */
  2643. locks *= 2;
  2644. *timeout = now + (2000 * locks); /* give the mpeg lock 800ms if sram is present */
  2645. dprintk("Deeper interleaver mode = %d on layer %d : timeout mult factor = %d => will use timeout = %d", deeper_interleaver, state->longest_intlv_layer, locks, *timeout);
  2646. *tune_state = CT_DEMOD_STEP_10;
  2647. } else
  2648. *tune_state = CT_DEMOD_STOP;
  2649. break;
  2650. case CT_DEMOD_STEP_10: /* 40 */
  2651. locks = dib8000_read_lock(fe);
  2652. if (locks&(1<<(7-state->longest_intlv_layer))) { /* mpeg lock : check the longest one */
  2653. dprintk("Mpeg locks [ L0 : %d | L1 : %d | L2 : %d ]", (locks>>7)&0x1, (locks>>6)&0x1, (locks>>5)&0x1);
  2654. if (c->isdbt_sb_mode
  2655. && c->isdbt_sb_subchannel < 14
  2656. && !state->differential_constellation)
  2657. /* signal to the upper layer, that there was a channel found and the parameters can be read */
  2658. state->status = FE_STATUS_DEMOD_SUCCESS;
  2659. else
  2660. state->status = FE_STATUS_DATA_LOCKED;
  2661. *tune_state = CT_DEMOD_STOP;
  2662. } else if (now > *timeout) {
  2663. if (c->isdbt_sb_mode
  2664. && c->isdbt_sb_subchannel < 14
  2665. && !state->differential_constellation) { /* continue to try init prbs autosearch */
  2666. state->subchannel += 3;
  2667. *tune_state = CT_DEMOD_STEP_11;
  2668. } else { /* we are done mpeg of the longest interleaver xas not locking but let's try if an other layer has locked in the same time */
  2669. if (locks & (0x7<<5)) {
  2670. dprintk("Mpeg locks [ L0 : %d | L1 : %d | L2 : %d ]", (locks>>7)&0x1, (locks>>6)&0x1, (locks>>5)&0x1);
  2671. state->status = FE_STATUS_DATA_LOCKED;
  2672. } else
  2673. state->status = FE_STATUS_TUNE_FAILED;
  2674. *tune_state = CT_DEMOD_STOP;
  2675. }
  2676. }
  2677. break;
  2678. case CT_DEMOD_STEP_11: /* 41 : init prbs autosearch */
  2679. if (state->subchannel <= 41) {
  2680. dib8000_set_subchannel_prbs(state, dib8000_get_init_prbs(state, state->subchannel));
  2681. *tune_state = CT_DEMOD_STEP_9;
  2682. } else {
  2683. *tune_state = CT_DEMOD_STOP;
  2684. state->status = FE_STATUS_TUNE_FAILED;
  2685. }
  2686. break;
  2687. default:
  2688. break;
  2689. }
  2690. /* tuning is finished - cleanup the demod */
  2691. switch (*tune_state) {
  2692. case CT_DEMOD_STOP: /* (42) */
  2693. #ifdef DIB8000_AGC_FREEZE
  2694. if ((state->revision != 0x8090) && (state->agc1_max != 0)) {
  2695. dib8000_write_word(state, 108, state->agc1_max);
  2696. dib8000_write_word(state, 109, state->agc1_min);
  2697. dib8000_write_word(state, 110, state->agc2_max);
  2698. dib8000_write_word(state, 111, state->agc2_min);
  2699. state->agc1_max = 0;
  2700. state->agc1_min = 0;
  2701. state->agc2_max = 0;
  2702. state->agc2_min = 0;
  2703. }
  2704. #endif
  2705. ret = FE_CALLBACK_TIME_NEVER;
  2706. break;
  2707. default:
  2708. break;
  2709. }
  2710. if ((ret > 0) && (*tune_state > CT_DEMOD_STEP_3))
  2711. return ret * state->symbol_duration;
  2712. if ((ret > 0) && (ret < state->symbol_duration))
  2713. return state->symbol_duration; /* at least one symbol */
  2714. return ret;
  2715. }
  2716. static int dib8000_wakeup(struct dvb_frontend *fe)
  2717. {
  2718. struct dib8000_state *state = fe->demodulator_priv;
  2719. u8 index_frontend;
  2720. int ret;
  2721. dib8000_set_power_mode(state, DIB8000_POWER_ALL);
  2722. dib8000_set_adc_state(state, DIBX000_ADC_ON);
  2723. if (dib8000_set_adc_state(state, DIBX000_SLOW_ADC_ON) != 0)
  2724. dprintk("could not start Slow ADC");
  2725. if (state->revision == 0x8090)
  2726. dib8000_sad_calib(state);
  2727. for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
  2728. ret = state->fe[index_frontend]->ops.init(state->fe[index_frontend]);
  2729. if (ret < 0)
  2730. return ret;
  2731. }
  2732. return 0;
  2733. }
  2734. static int dib8000_sleep(struct dvb_frontend *fe)
  2735. {
  2736. struct dib8000_state *state = fe->demodulator_priv;
  2737. u8 index_frontend;
  2738. int ret;
  2739. for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
  2740. ret = state->fe[index_frontend]->ops.sleep(state->fe[index_frontend]);
  2741. if (ret < 0)
  2742. return ret;
  2743. }
  2744. if (state->revision != 0x8090)
  2745. dib8000_set_output_mode(fe, OUTMODE_HIGH_Z);
  2746. dib8000_set_power_mode(state, DIB8000_POWER_INTERFACE_ONLY);
  2747. return dib8000_set_adc_state(state, DIBX000_SLOW_ADC_OFF) | dib8000_set_adc_state(state, DIBX000_ADC_OFF);
  2748. }
  2749. static int dib8000_get_frontend(struct dvb_frontend *fe)
  2750. {
  2751. struct dib8000_state *state = fe->demodulator_priv;
  2752. u16 i, val = 0;
  2753. fe_status_t stat;
  2754. u8 index_frontend, sub_index_frontend;
  2755. fe->dtv_property_cache.bandwidth_hz = 6000000;
  2756. for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
  2757. state->fe[index_frontend]->ops.read_status(state->fe[index_frontend], &stat);
  2758. if (stat&FE_HAS_SYNC) {
  2759. dprintk("TMCC lock on the slave%i", index_frontend);
  2760. /* synchronize the cache with the other frontends */
  2761. state->fe[index_frontend]->ops.get_frontend(state->fe[index_frontend]);
  2762. for (sub_index_frontend = 0; (sub_index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[sub_index_frontend] != NULL); sub_index_frontend++) {
  2763. if (sub_index_frontend != index_frontend) {
  2764. state->fe[sub_index_frontend]->dtv_property_cache.isdbt_sb_mode = state->fe[index_frontend]->dtv_property_cache.isdbt_sb_mode;
  2765. state->fe[sub_index_frontend]->dtv_property_cache.inversion = state->fe[index_frontend]->dtv_property_cache.inversion;
  2766. state->fe[sub_index_frontend]->dtv_property_cache.transmission_mode = state->fe[index_frontend]->dtv_property_cache.transmission_mode;
  2767. state->fe[sub_index_frontend]->dtv_property_cache.guard_interval = state->fe[index_frontend]->dtv_property_cache.guard_interval;
  2768. state->fe[sub_index_frontend]->dtv_property_cache.isdbt_partial_reception = state->fe[index_frontend]->dtv_property_cache.isdbt_partial_reception;
  2769. for (i = 0; i < 3; i++) {
  2770. state->fe[sub_index_frontend]->dtv_property_cache.layer[i].segment_count = state->fe[index_frontend]->dtv_property_cache.layer[i].segment_count;
  2771. state->fe[sub_index_frontend]->dtv_property_cache.layer[i].interleaving = state->fe[index_frontend]->dtv_property_cache.layer[i].interleaving;
  2772. state->fe[sub_index_frontend]->dtv_property_cache.layer[i].fec = state->fe[index_frontend]->dtv_property_cache.layer[i].fec;
  2773. state->fe[sub_index_frontend]->dtv_property_cache.layer[i].modulation = state->fe[index_frontend]->dtv_property_cache.layer[i].modulation;
  2774. }
  2775. }
  2776. }
  2777. return 0;
  2778. }
  2779. }
  2780. fe->dtv_property_cache.isdbt_sb_mode = dib8000_read_word(state, 508) & 0x1;
  2781. if (state->revision == 0x8090)
  2782. val = dib8000_read_word(state, 572);
  2783. else
  2784. val = dib8000_read_word(state, 570);
  2785. fe->dtv_property_cache.inversion = (val & 0x40) >> 6;
  2786. switch ((val & 0x30) >> 4) {
  2787. case 1:
  2788. fe->dtv_property_cache.transmission_mode = TRANSMISSION_MODE_2K;
  2789. break;
  2790. case 3:
  2791. default:
  2792. fe->dtv_property_cache.transmission_mode = TRANSMISSION_MODE_8K;
  2793. break;
  2794. }
  2795. switch (val & 0x3) {
  2796. case 0:
  2797. fe->dtv_property_cache.guard_interval = GUARD_INTERVAL_1_32;
  2798. dprintk("dib8000_get_frontend GI = 1/32 ");
  2799. break;
  2800. case 1:
  2801. fe->dtv_property_cache.guard_interval = GUARD_INTERVAL_1_16;
  2802. dprintk("dib8000_get_frontend GI = 1/16 ");
  2803. break;
  2804. case 2:
  2805. dprintk("dib8000_get_frontend GI = 1/8 ");
  2806. fe->dtv_property_cache.guard_interval = GUARD_INTERVAL_1_8;
  2807. break;
  2808. case 3:
  2809. dprintk("dib8000_get_frontend GI = 1/4 ");
  2810. fe->dtv_property_cache.guard_interval = GUARD_INTERVAL_1_4;
  2811. break;
  2812. }
  2813. val = dib8000_read_word(state, 505);
  2814. fe->dtv_property_cache.isdbt_partial_reception = val & 1;
  2815. dprintk("dib8000_get_frontend : partial_reception = %d ", fe->dtv_property_cache.isdbt_partial_reception);
  2816. for (i = 0; i < 3; i++) {
  2817. val = dib8000_read_word(state, 493 + i);
  2818. fe->dtv_property_cache.layer[i].segment_count = val & 0x0F;
  2819. dprintk("dib8000_get_frontend : Layer %d segments = %d ", i, fe->dtv_property_cache.layer[i].segment_count);
  2820. val = dib8000_read_word(state, 499 + i);
  2821. fe->dtv_property_cache.layer[i].interleaving = val & 0x3;
  2822. dprintk("dib8000_get_frontend : Layer %d time_intlv = %d ", i, fe->dtv_property_cache.layer[i].interleaving);
  2823. val = dib8000_read_word(state, 481 + i);
  2824. switch (val & 0x7) {
  2825. case 1:
  2826. fe->dtv_property_cache.layer[i].fec = FEC_1_2;
  2827. dprintk("dib8000_get_frontend : Layer %d Code Rate = 1/2 ", i);
  2828. break;
  2829. case 2:
  2830. fe->dtv_property_cache.layer[i].fec = FEC_2_3;
  2831. dprintk("dib8000_get_frontend : Layer %d Code Rate = 2/3 ", i);
  2832. break;
  2833. case 3:
  2834. fe->dtv_property_cache.layer[i].fec = FEC_3_4;
  2835. dprintk("dib8000_get_frontend : Layer %d Code Rate = 3/4 ", i);
  2836. break;
  2837. case 5:
  2838. fe->dtv_property_cache.layer[i].fec = FEC_5_6;
  2839. dprintk("dib8000_get_frontend : Layer %d Code Rate = 5/6 ", i);
  2840. break;
  2841. default:
  2842. fe->dtv_property_cache.layer[i].fec = FEC_7_8;
  2843. dprintk("dib8000_get_frontend : Layer %d Code Rate = 7/8 ", i);
  2844. break;
  2845. }
  2846. val = dib8000_read_word(state, 487 + i);
  2847. switch (val & 0x3) {
  2848. case 0:
  2849. dprintk("dib8000_get_frontend : Layer %d DQPSK ", i);
  2850. fe->dtv_property_cache.layer[i].modulation = DQPSK;
  2851. break;
  2852. case 1:
  2853. fe->dtv_property_cache.layer[i].modulation = QPSK;
  2854. dprintk("dib8000_get_frontend : Layer %d QPSK ", i);
  2855. break;
  2856. case 2:
  2857. fe->dtv_property_cache.layer[i].modulation = QAM_16;
  2858. dprintk("dib8000_get_frontend : Layer %d QAM16 ", i);
  2859. break;
  2860. case 3:
  2861. default:
  2862. dprintk("dib8000_get_frontend : Layer %d QAM64 ", i);
  2863. fe->dtv_property_cache.layer[i].modulation = QAM_64;
  2864. break;
  2865. }
  2866. }
  2867. /* synchronize the cache with the other frontends */
  2868. for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
  2869. state->fe[index_frontend]->dtv_property_cache.isdbt_sb_mode = fe->dtv_property_cache.isdbt_sb_mode;
  2870. state->fe[index_frontend]->dtv_property_cache.inversion = fe->dtv_property_cache.inversion;
  2871. state->fe[index_frontend]->dtv_property_cache.transmission_mode = fe->dtv_property_cache.transmission_mode;
  2872. state->fe[index_frontend]->dtv_property_cache.guard_interval = fe->dtv_property_cache.guard_interval;
  2873. state->fe[index_frontend]->dtv_property_cache.isdbt_partial_reception = fe->dtv_property_cache.isdbt_partial_reception;
  2874. for (i = 0; i < 3; i++) {
  2875. state->fe[index_frontend]->dtv_property_cache.layer[i].segment_count = fe->dtv_property_cache.layer[i].segment_count;
  2876. state->fe[index_frontend]->dtv_property_cache.layer[i].interleaving = fe->dtv_property_cache.layer[i].interleaving;
  2877. state->fe[index_frontend]->dtv_property_cache.layer[i].fec = fe->dtv_property_cache.layer[i].fec;
  2878. state->fe[index_frontend]->dtv_property_cache.layer[i].modulation = fe->dtv_property_cache.layer[i].modulation;
  2879. }
  2880. }
  2881. return 0;
  2882. }
  2883. static int dib8000_set_frontend(struct dvb_frontend *fe)
  2884. {
  2885. struct dib8000_state *state = fe->demodulator_priv;
  2886. struct dtv_frontend_properties *c = &state->fe[0]->dtv_property_cache;
  2887. int l, i, active, time, time_slave = FE_CALLBACK_TIME_NEVER;
  2888. u8 exit_condition, index_frontend;
  2889. u32 delay, callback_time;
  2890. if (c->frequency == 0) {
  2891. dprintk("dib8000: must at least specify frequency ");
  2892. return 0;
  2893. }
  2894. if (c->bandwidth_hz == 0) {
  2895. dprintk("dib8000: no bandwidth specified, set to default ");
  2896. c->bandwidth_hz = 6000000;
  2897. }
  2898. for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
  2899. /* synchronization of the cache */
  2900. state->fe[index_frontend]->dtv_property_cache.delivery_system = SYS_ISDBT;
  2901. memcpy(&state->fe[index_frontend]->dtv_property_cache, &fe->dtv_property_cache, sizeof(struct dtv_frontend_properties));
  2902. /* set output mode and diversity input */
  2903. if (state->revision != 0x8090) {
  2904. dib8000_set_diversity_in(state->fe[index_frontend], 1);
  2905. if (index_frontend != 0)
  2906. dib8000_set_output_mode(state->fe[index_frontend],
  2907. OUTMODE_DIVERSITY);
  2908. else
  2909. dib8000_set_output_mode(state->fe[0], OUTMODE_HIGH_Z);
  2910. } else {
  2911. dib8096p_set_diversity_in(state->fe[index_frontend], 1);
  2912. if (index_frontend != 0)
  2913. dib8096p_set_output_mode(state->fe[index_frontend],
  2914. OUTMODE_DIVERSITY);
  2915. else
  2916. dib8096p_set_output_mode(state->fe[0], OUTMODE_HIGH_Z);
  2917. }
  2918. /* tune the tuner */
  2919. if (state->fe[index_frontend]->ops.tuner_ops.set_params)
  2920. state->fe[index_frontend]->ops.tuner_ops.set_params(state->fe[index_frontend]);
  2921. dib8000_set_tune_state(state->fe[index_frontend], CT_AGC_START);
  2922. }
  2923. /* turn off the diversity of the last chip */
  2924. if (state->revision != 0x8090)
  2925. dib8000_set_diversity_in(state->fe[index_frontend - 1], 0);
  2926. else
  2927. dib8096p_set_diversity_in(state->fe[index_frontend - 1], 0);
  2928. /* start up the AGC */
  2929. do {
  2930. time = dib8000_agc_startup(state->fe[0]);
  2931. for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
  2932. time_slave = dib8000_agc_startup(state->fe[index_frontend]);
  2933. if (time == FE_CALLBACK_TIME_NEVER)
  2934. time = time_slave;
  2935. else if ((time_slave != FE_CALLBACK_TIME_NEVER) && (time_slave > time))
  2936. time = time_slave;
  2937. }
  2938. if (time != FE_CALLBACK_TIME_NEVER)
  2939. msleep(time / 10);
  2940. else
  2941. break;
  2942. exit_condition = 1;
  2943. for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
  2944. if (dib8000_get_tune_state(state->fe[index_frontend]) != CT_AGC_STOP) {
  2945. exit_condition = 0;
  2946. break;
  2947. }
  2948. }
  2949. } while (exit_condition == 0);
  2950. for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++)
  2951. dib8000_set_tune_state(state->fe[index_frontend], CT_DEMOD_START);
  2952. active = 1;
  2953. do {
  2954. callback_time = FE_CALLBACK_TIME_NEVER;
  2955. for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
  2956. delay = dib8000_tune(state->fe[index_frontend]);
  2957. if (delay != FE_CALLBACK_TIME_NEVER)
  2958. delay += systime();
  2959. /* we are in autosearch */
  2960. if (state->channel_parameters_set == 0) { /* searching */
  2961. if ((dib8000_get_status(state->fe[index_frontend]) == FE_STATUS_DEMOD_SUCCESS) || (dib8000_get_status(state->fe[index_frontend]) == FE_STATUS_FFT_SUCCESS)) {
  2962. dprintk("autosearch succeeded on fe%i", index_frontend);
  2963. dib8000_get_frontend(state->fe[index_frontend]); /* we read the channel parameters from the frontend which was successful */
  2964. state->channel_parameters_set = 1;
  2965. for (l = 0; (l < MAX_NUMBER_OF_FRONTENDS) && (state->fe[l] != NULL); l++) {
  2966. if (l != index_frontend) { /* and for all frontend except the successful one */
  2967. dib8000_tune_restart_from_demod(state->fe[l]);
  2968. state->fe[l]->dtv_property_cache.isdbt_sb_mode = state->fe[index_frontend]->dtv_property_cache.isdbt_sb_mode;
  2969. state->fe[l]->dtv_property_cache.inversion = state->fe[index_frontend]->dtv_property_cache.inversion;
  2970. state->fe[l]->dtv_property_cache.transmission_mode = state->fe[index_frontend]->dtv_property_cache.transmission_mode;
  2971. state->fe[l]->dtv_property_cache.guard_interval = state->fe[index_frontend]->dtv_property_cache.guard_interval;
  2972. state->fe[l]->dtv_property_cache.isdbt_partial_reception = state->fe[index_frontend]->dtv_property_cache.isdbt_partial_reception;
  2973. for (i = 0; i < 3; i++) {
  2974. state->fe[l]->dtv_property_cache.layer[i].segment_count = state->fe[index_frontend]->dtv_property_cache.layer[i].segment_count;
  2975. state->fe[l]->dtv_property_cache.layer[i].interleaving = state->fe[index_frontend]->dtv_property_cache.layer[i].interleaving;
  2976. state->fe[l]->dtv_property_cache.layer[i].fec = state->fe[index_frontend]->dtv_property_cache.layer[i].fec;
  2977. state->fe[l]->dtv_property_cache.layer[i].modulation = state->fe[index_frontend]->dtv_property_cache.layer[i].modulation;
  2978. }
  2979. }
  2980. }
  2981. }
  2982. }
  2983. if (delay < callback_time)
  2984. callback_time = delay;
  2985. }
  2986. /* tuning is done when the master frontend is done (failed or success) */
  2987. if (dib8000_get_status(state->fe[0]) == FE_STATUS_TUNE_FAILED ||
  2988. dib8000_get_status(state->fe[0]) == FE_STATUS_LOCKED ||
  2989. dib8000_get_status(state->fe[0]) == FE_STATUS_DATA_LOCKED) {
  2990. active = 0;
  2991. /* we need to wait for all frontends to be finished */
  2992. for (index_frontend = 0; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
  2993. if (dib8000_get_tune_state(state->fe[index_frontend]) != CT_DEMOD_STOP)
  2994. active = 1;
  2995. }
  2996. if (active == 0)
  2997. dprintk("tuning done with status %d", dib8000_get_status(state->fe[0]));
  2998. }
  2999. if ((active == 1) && (callback_time == FE_CALLBACK_TIME_NEVER)) {
  3000. dprintk("strange callback time something went wrong");
  3001. active = 0;
  3002. }
  3003. while ((active == 1) && (systime() < callback_time))
  3004. msleep(100);
  3005. } while (active);
  3006. /* set output mode */
  3007. if (state->revision != 0x8090)
  3008. dib8000_set_output_mode(state->fe[0], state->cfg.output_mode);
  3009. else {
  3010. dib8096p_set_output_mode(state->fe[0], state->cfg.output_mode);
  3011. if (state->cfg.enMpegOutput == 0) {
  3012. dib8096p_setDibTxMux(state, MPEG_ON_DIBTX);
  3013. dib8096p_setHostBusMux(state, DIBTX_ON_HOSTBUS);
  3014. }
  3015. }
  3016. return 0;
  3017. }
  3018. static int dib8000_read_status(struct dvb_frontend *fe, fe_status_t * stat)
  3019. {
  3020. struct dib8000_state *state = fe->demodulator_priv;
  3021. u16 lock_slave = 0, lock;
  3022. u8 index_frontend;
  3023. lock = dib8000_read_lock(fe);
  3024. for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++)
  3025. lock_slave |= dib8000_read_lock(state->fe[index_frontend]);
  3026. *stat = 0;
  3027. if (((lock >> 13) & 1) || ((lock_slave >> 13) & 1))
  3028. *stat |= FE_HAS_SIGNAL;
  3029. if (((lock >> 8) & 1) || ((lock_slave >> 8) & 1)) /* Equal */
  3030. *stat |= FE_HAS_CARRIER;
  3031. if ((((lock >> 1) & 0xf) == 0xf) || (((lock_slave >> 1) & 0xf) == 0xf)) /* TMCC_SYNC */
  3032. *stat |= FE_HAS_SYNC;
  3033. if ((((lock >> 12) & 1) || ((lock_slave >> 12) & 1)) && ((lock >> 5) & 7)) /* FEC MPEG */
  3034. *stat |= FE_HAS_LOCK;
  3035. if (((lock >> 12) & 1) || ((lock_slave >> 12) & 1)) {
  3036. lock = dib8000_read_word(state, 554); /* Viterbi Layer A */
  3037. if (lock & 0x01)
  3038. *stat |= FE_HAS_VITERBI;
  3039. lock = dib8000_read_word(state, 555); /* Viterbi Layer B */
  3040. if (lock & 0x01)
  3041. *stat |= FE_HAS_VITERBI;
  3042. lock = dib8000_read_word(state, 556); /* Viterbi Layer C */
  3043. if (lock & 0x01)
  3044. *stat |= FE_HAS_VITERBI;
  3045. }
  3046. return 0;
  3047. }
  3048. static int dib8000_read_ber(struct dvb_frontend *fe, u32 * ber)
  3049. {
  3050. struct dib8000_state *state = fe->demodulator_priv;
  3051. /* 13 segments */
  3052. if (state->revision == 0x8090)
  3053. *ber = (dib8000_read_word(state, 562) << 16) |
  3054. dib8000_read_word(state, 563);
  3055. else
  3056. *ber = (dib8000_read_word(state, 560) << 16) |
  3057. dib8000_read_word(state, 561);
  3058. return 0;
  3059. }
  3060. static int dib8000_read_unc_blocks(struct dvb_frontend *fe, u32 * unc)
  3061. {
  3062. struct dib8000_state *state = fe->demodulator_priv;
  3063. /* packet error on 13 seg */
  3064. if (state->revision == 0x8090)
  3065. *unc = dib8000_read_word(state, 567);
  3066. else
  3067. *unc = dib8000_read_word(state, 565);
  3068. return 0;
  3069. }
  3070. static int dib8000_read_signal_strength(struct dvb_frontend *fe, u16 * strength)
  3071. {
  3072. struct dib8000_state *state = fe->demodulator_priv;
  3073. u8 index_frontend;
  3074. u16 val;
  3075. *strength = 0;
  3076. for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++) {
  3077. state->fe[index_frontend]->ops.read_signal_strength(state->fe[index_frontend], &val);
  3078. if (val > 65535 - *strength)
  3079. *strength = 65535;
  3080. else
  3081. *strength += val;
  3082. }
  3083. val = 65535 - dib8000_read_word(state, 390);
  3084. if (val > 65535 - *strength)
  3085. *strength = 65535;
  3086. else
  3087. *strength += val;
  3088. return 0;
  3089. }
  3090. static u32 dib8000_get_snr(struct dvb_frontend *fe)
  3091. {
  3092. struct dib8000_state *state = fe->demodulator_priv;
  3093. u32 n, s, exp;
  3094. u16 val;
  3095. if (state->revision != 0x8090)
  3096. val = dib8000_read_word(state, 542);
  3097. else
  3098. val = dib8000_read_word(state, 544);
  3099. n = (val >> 6) & 0xff;
  3100. exp = (val & 0x3f);
  3101. if ((exp & 0x20) != 0)
  3102. exp -= 0x40;
  3103. n <<= exp+16;
  3104. if (state->revision != 0x8090)
  3105. val = dib8000_read_word(state, 543);
  3106. else
  3107. val = dib8000_read_word(state, 545);
  3108. s = (val >> 6) & 0xff;
  3109. exp = (val & 0x3f);
  3110. if ((exp & 0x20) != 0)
  3111. exp -= 0x40;
  3112. s <<= exp+16;
  3113. if (n > 0) {
  3114. u32 t = (s/n) << 16;
  3115. return t + ((s << 16) - n*t) / n;
  3116. }
  3117. return 0xffffffff;
  3118. }
  3119. static int dib8000_read_snr(struct dvb_frontend *fe, u16 * snr)
  3120. {
  3121. struct dib8000_state *state = fe->demodulator_priv;
  3122. u8 index_frontend;
  3123. u32 snr_master;
  3124. snr_master = dib8000_get_snr(fe);
  3125. for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL); index_frontend++)
  3126. snr_master += dib8000_get_snr(state->fe[index_frontend]);
  3127. if ((snr_master >> 16) != 0) {
  3128. snr_master = 10*intlog10(snr_master>>16);
  3129. *snr = snr_master / ((1 << 24) / 10);
  3130. }
  3131. else
  3132. *snr = 0;
  3133. return 0;
  3134. }
  3135. int dib8000_set_slave_frontend(struct dvb_frontend *fe, struct dvb_frontend *fe_slave)
  3136. {
  3137. struct dib8000_state *state = fe->demodulator_priv;
  3138. u8 index_frontend = 1;
  3139. while ((index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL))
  3140. index_frontend++;
  3141. if (index_frontend < MAX_NUMBER_OF_FRONTENDS) {
  3142. dprintk("set slave fe %p to index %i", fe_slave, index_frontend);
  3143. state->fe[index_frontend] = fe_slave;
  3144. return 0;
  3145. }
  3146. dprintk("too many slave frontend");
  3147. return -ENOMEM;
  3148. }
  3149. EXPORT_SYMBOL(dib8000_set_slave_frontend);
  3150. int dib8000_remove_slave_frontend(struct dvb_frontend *fe)
  3151. {
  3152. struct dib8000_state *state = fe->demodulator_priv;
  3153. u8 index_frontend = 1;
  3154. while ((index_frontend < MAX_NUMBER_OF_FRONTENDS) && (state->fe[index_frontend] != NULL))
  3155. index_frontend++;
  3156. if (index_frontend != 1) {
  3157. dprintk("remove slave fe %p (index %i)", state->fe[index_frontend-1], index_frontend-1);
  3158. state->fe[index_frontend] = NULL;
  3159. return 0;
  3160. }
  3161. dprintk("no frontend to be removed");
  3162. return -ENODEV;
  3163. }
  3164. EXPORT_SYMBOL(dib8000_remove_slave_frontend);
  3165. struct dvb_frontend *dib8000_get_slave_frontend(struct dvb_frontend *fe, int slave_index)
  3166. {
  3167. struct dib8000_state *state = fe->demodulator_priv;
  3168. if (slave_index >= MAX_NUMBER_OF_FRONTENDS)
  3169. return NULL;
  3170. return state->fe[slave_index];
  3171. }
  3172. EXPORT_SYMBOL(dib8000_get_slave_frontend);
  3173. int dib8000_i2c_enumeration(struct i2c_adapter *host, int no_of_demods,
  3174. u8 default_addr, u8 first_addr, u8 is_dib8096p)
  3175. {
  3176. int k = 0, ret = 0;
  3177. u8 new_addr = 0;
  3178. struct i2c_device client = {.adap = host };
  3179. client.i2c_write_buffer = kzalloc(4 * sizeof(u8), GFP_KERNEL);
  3180. if (!client.i2c_write_buffer) {
  3181. dprintk("%s: not enough memory", __func__);
  3182. return -ENOMEM;
  3183. }
  3184. client.i2c_read_buffer = kzalloc(4 * sizeof(u8), GFP_KERNEL);
  3185. if (!client.i2c_read_buffer) {
  3186. dprintk("%s: not enough memory", __func__);
  3187. ret = -ENOMEM;
  3188. goto error_memory_read;
  3189. }
  3190. client.i2c_buffer_lock = kzalloc(sizeof(struct mutex), GFP_KERNEL);
  3191. if (!client.i2c_buffer_lock) {
  3192. dprintk("%s: not enough memory", __func__);
  3193. ret = -ENOMEM;
  3194. goto error_memory_lock;
  3195. }
  3196. mutex_init(client.i2c_buffer_lock);
  3197. for (k = no_of_demods - 1; k >= 0; k--) {
  3198. /* designated i2c address */
  3199. new_addr = first_addr + (k << 1);
  3200. client.addr = new_addr;
  3201. if (!is_dib8096p)
  3202. dib8000_i2c_write16(&client, 1287, 0x0003); /* sram lead in, rdy */
  3203. if (dib8000_identify(&client) == 0) {
  3204. /* sram lead in, rdy */
  3205. if (!is_dib8096p)
  3206. dib8000_i2c_write16(&client, 1287, 0x0003);
  3207. client.addr = default_addr;
  3208. if (dib8000_identify(&client) == 0) {
  3209. dprintk("#%d: not identified", k);
  3210. ret = -EINVAL;
  3211. goto error;
  3212. }
  3213. }
  3214. /* start diversity to pull_down div_str - just for i2c-enumeration */
  3215. dib8000_i2c_write16(&client, 1286, (1 << 10) | (4 << 6));
  3216. /* set new i2c address and force divstart */
  3217. dib8000_i2c_write16(&client, 1285, (new_addr << 2) | 0x2);
  3218. client.addr = new_addr;
  3219. dib8000_identify(&client);
  3220. dprintk("IC %d initialized (to i2c_address 0x%x)", k, new_addr);
  3221. }
  3222. for (k = 0; k < no_of_demods; k++) {
  3223. new_addr = first_addr | (k << 1);
  3224. client.addr = new_addr;
  3225. // unforce divstr
  3226. dib8000_i2c_write16(&client, 1285, new_addr << 2);
  3227. /* deactivate div - it was just for i2c-enumeration */
  3228. dib8000_i2c_write16(&client, 1286, 0);
  3229. }
  3230. error:
  3231. kfree(client.i2c_buffer_lock);
  3232. error_memory_lock:
  3233. kfree(client.i2c_read_buffer);
  3234. error_memory_read:
  3235. kfree(client.i2c_write_buffer);
  3236. return ret;
  3237. }
  3238. EXPORT_SYMBOL(dib8000_i2c_enumeration);
  3239. static int dib8000_fe_get_tune_settings(struct dvb_frontend *fe, struct dvb_frontend_tune_settings *tune)
  3240. {
  3241. tune->min_delay_ms = 1000;
  3242. tune->step_size = 0;
  3243. tune->max_drift = 0;
  3244. return 0;
  3245. }
  3246. static void dib8000_release(struct dvb_frontend *fe)
  3247. {
  3248. struct dib8000_state *st = fe->demodulator_priv;
  3249. u8 index_frontend;
  3250. for (index_frontend = 1; (index_frontend < MAX_NUMBER_OF_FRONTENDS) && (st->fe[index_frontend] != NULL); index_frontend++)
  3251. dvb_frontend_detach(st->fe[index_frontend]);
  3252. dibx000_exit_i2c_master(&st->i2c_master);
  3253. i2c_del_adapter(&st->dib8096p_tuner_adap);
  3254. kfree(st->fe[0]);
  3255. kfree(st);
  3256. }
  3257. struct i2c_adapter *dib8000_get_i2c_master(struct dvb_frontend *fe, enum dibx000_i2c_interface intf, int gating)
  3258. {
  3259. struct dib8000_state *st = fe->demodulator_priv;
  3260. return dibx000_get_i2c_adapter(&st->i2c_master, intf, gating);
  3261. }
  3262. EXPORT_SYMBOL(dib8000_get_i2c_master);
  3263. int dib8000_pid_filter_ctrl(struct dvb_frontend *fe, u8 onoff)
  3264. {
  3265. struct dib8000_state *st = fe->demodulator_priv;
  3266. u16 val = dib8000_read_word(st, 299) & 0xffef;
  3267. val |= (onoff & 0x1) << 4;
  3268. dprintk("pid filter enabled %d", onoff);
  3269. return dib8000_write_word(st, 299, val);
  3270. }
  3271. EXPORT_SYMBOL(dib8000_pid_filter_ctrl);
  3272. int dib8000_pid_filter(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff)
  3273. {
  3274. struct dib8000_state *st = fe->demodulator_priv;
  3275. dprintk("Index %x, PID %d, OnOff %d", id, pid, onoff);
  3276. return dib8000_write_word(st, 305 + id, onoff ? (1 << 13) | pid : 0);
  3277. }
  3278. EXPORT_SYMBOL(dib8000_pid_filter);
  3279. static const struct dvb_frontend_ops dib8000_ops = {
  3280. .delsys = { SYS_ISDBT },
  3281. .info = {
  3282. .name = "DiBcom 8000 ISDB-T",
  3283. .frequency_min = 44250000,
  3284. .frequency_max = 867250000,
  3285. .frequency_stepsize = 62500,
  3286. .caps = FE_CAN_INVERSION_AUTO |
  3287. FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  3288. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  3289. FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
  3290. FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO | FE_CAN_RECOVER | FE_CAN_HIERARCHY_AUTO,
  3291. },
  3292. .release = dib8000_release,
  3293. .init = dib8000_wakeup,
  3294. .sleep = dib8000_sleep,
  3295. .set_frontend = dib8000_set_frontend,
  3296. .get_tune_settings = dib8000_fe_get_tune_settings,
  3297. .get_frontend = dib8000_get_frontend,
  3298. .read_status = dib8000_read_status,
  3299. .read_ber = dib8000_read_ber,
  3300. .read_signal_strength = dib8000_read_signal_strength,
  3301. .read_snr = dib8000_read_snr,
  3302. .read_ucblocks = dib8000_read_unc_blocks,
  3303. };
  3304. struct dvb_frontend *dib8000_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib8000_config *cfg)
  3305. {
  3306. struct dvb_frontend *fe;
  3307. struct dib8000_state *state;
  3308. dprintk("dib8000_attach");
  3309. state = kzalloc(sizeof(struct dib8000_state), GFP_KERNEL);
  3310. if (state == NULL)
  3311. return NULL;
  3312. fe = kzalloc(sizeof(struct dvb_frontend), GFP_KERNEL);
  3313. if (fe == NULL)
  3314. goto error;
  3315. memcpy(&state->cfg, cfg, sizeof(struct dib8000_config));
  3316. state->i2c.adap = i2c_adap;
  3317. state->i2c.addr = i2c_addr;
  3318. state->i2c.i2c_write_buffer = state->i2c_write_buffer;
  3319. state->i2c.i2c_read_buffer = state->i2c_read_buffer;
  3320. mutex_init(&state->i2c_buffer_lock);
  3321. state->i2c.i2c_buffer_lock = &state->i2c_buffer_lock;
  3322. state->gpio_val = cfg->gpio_val;
  3323. state->gpio_dir = cfg->gpio_dir;
  3324. /* Ensure the output mode remains at the previous default if it's
  3325. * not specifically set by the caller.
  3326. */
  3327. if ((state->cfg.output_mode != OUTMODE_MPEG2_SERIAL) && (state->cfg.output_mode != OUTMODE_MPEG2_PAR_GATED_CLK))
  3328. state->cfg.output_mode = OUTMODE_MPEG2_FIFO;
  3329. state->fe[0] = fe;
  3330. fe->demodulator_priv = state;
  3331. memcpy(&state->fe[0]->ops, &dib8000_ops, sizeof(struct dvb_frontend_ops));
  3332. state->timf_default = cfg->pll->timf;
  3333. if (dib8000_identify(&state->i2c) == 0)
  3334. goto error;
  3335. dibx000_init_i2c_master(&state->i2c_master, DIB8000, state->i2c.adap, state->i2c.addr);
  3336. /* init 8096p tuner adapter */
  3337. strncpy(state->dib8096p_tuner_adap.name, "DiB8096P tuner interface",
  3338. sizeof(state->dib8096p_tuner_adap.name));
  3339. state->dib8096p_tuner_adap.algo = &dib8096p_tuner_xfer_algo;
  3340. state->dib8096p_tuner_adap.algo_data = NULL;
  3341. state->dib8096p_tuner_adap.dev.parent = state->i2c.adap->dev.parent;
  3342. i2c_set_adapdata(&state->dib8096p_tuner_adap, state);
  3343. i2c_add_adapter(&state->dib8096p_tuner_adap);
  3344. dib8000_reset(fe);
  3345. dib8000_write_word(state, 285, (dib8000_read_word(state, 285) & ~0x60) | (3 << 5)); /* ber_rs_len = 3 */
  3346. state->current_demod_bw = 6000;
  3347. return fe;
  3348. error:
  3349. kfree(state);
  3350. return NULL;
  3351. }
  3352. EXPORT_SYMBOL(dib8000_attach);
  3353. MODULE_AUTHOR("Olivier Grenie <Olivier.Grenie@dibcom.fr, " "Patrick Boettcher <pboettcher@dibcom.fr>");
  3354. MODULE_DESCRIPTION("Driver for the DiBcom 8000 ISDB-T demodulator");
  3355. MODULE_LICENSE("GPL");