dib7000p.c 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841
  1. /*
  2. * Linux-DVB Driver for DiBcom's second generation DiB7000P (PC).
  3. *
  4. * Copyright (C) 2005-7 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 <asm/div64.h>
  15. #include "dvb_math.h"
  16. #include "dvb_frontend.h"
  17. #include "dib7000p.h"
  18. static int debug;
  19. module_param(debug, int, 0644);
  20. MODULE_PARM_DESC(debug, "turn on debugging (default: 0)");
  21. static int buggy_sfn_workaround;
  22. module_param(buggy_sfn_workaround, int, 0644);
  23. MODULE_PARM_DESC(buggy_sfn_workaround, "Enable work-around for buggy SFNs (default: 0)");
  24. #define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiB7000P: "); printk(args); printk("\n"); } } while (0)
  25. struct i2c_device {
  26. struct i2c_adapter *i2c_adap;
  27. u8 i2c_addr;
  28. };
  29. struct dib7000p_state {
  30. struct dvb_frontend demod;
  31. struct dib7000p_config cfg;
  32. u8 i2c_addr;
  33. struct i2c_adapter *i2c_adap;
  34. struct dibx000_i2c_master i2c_master;
  35. u16 wbd_ref;
  36. u8 current_band;
  37. u32 current_bandwidth;
  38. struct dibx000_agc_config *current_agc;
  39. u32 timf;
  40. u8 div_force_off:1;
  41. u8 div_state:1;
  42. u16 div_sync_wait;
  43. u8 agc_state;
  44. u16 gpio_dir;
  45. u16 gpio_val;
  46. u8 sfn_workaround_active:1;
  47. #define SOC7090 0x7090
  48. u16 version;
  49. u16 tuner_enable;
  50. struct i2c_adapter dib7090_tuner_adap;
  51. /* for the I2C transfer */
  52. struct i2c_msg msg[2];
  53. u8 i2c_write_buffer[4];
  54. u8 i2c_read_buffer[2];
  55. struct mutex i2c_buffer_lock;
  56. u8 input_mode_mpeg;
  57. /* for DVBv5 stats */
  58. s64 old_ucb;
  59. unsigned long per_jiffies_stats;
  60. unsigned long ber_jiffies_stats;
  61. unsigned long get_stats_time;
  62. };
  63. enum dib7000p_power_mode {
  64. DIB7000P_POWER_ALL = 0,
  65. DIB7000P_POWER_ANALOG_ADC,
  66. DIB7000P_POWER_INTERFACE_ONLY,
  67. };
  68. /* dib7090 specific fonctions */
  69. static int dib7090_set_output_mode(struct dvb_frontend *fe, int mode);
  70. static int dib7090_set_diversity_in(struct dvb_frontend *fe, int onoff);
  71. static void dib7090_setDibTxMux(struct dib7000p_state *state, int mode);
  72. static void dib7090_setHostBusMux(struct dib7000p_state *state, int mode);
  73. static u16 dib7000p_read_word(struct dib7000p_state *state, u16 reg)
  74. {
  75. u16 ret;
  76. if (mutex_lock_interruptible(&state->i2c_buffer_lock) < 0) {
  77. dprintk("could not acquire lock");
  78. return 0;
  79. }
  80. state->i2c_write_buffer[0] = reg >> 8;
  81. state->i2c_write_buffer[1] = reg & 0xff;
  82. memset(state->msg, 0, 2 * sizeof(struct i2c_msg));
  83. state->msg[0].addr = state->i2c_addr >> 1;
  84. state->msg[0].flags = 0;
  85. state->msg[0].buf = state->i2c_write_buffer;
  86. state->msg[0].len = 2;
  87. state->msg[1].addr = state->i2c_addr >> 1;
  88. state->msg[1].flags = I2C_M_RD;
  89. state->msg[1].buf = state->i2c_read_buffer;
  90. state->msg[1].len = 2;
  91. if (i2c_transfer(state->i2c_adap, state->msg, 2) != 2)
  92. dprintk("i2c read error on %d", reg);
  93. ret = (state->i2c_read_buffer[0] << 8) | state->i2c_read_buffer[1];
  94. mutex_unlock(&state->i2c_buffer_lock);
  95. return ret;
  96. }
  97. static int dib7000p_write_word(struct dib7000p_state *state, u16 reg, u16 val)
  98. {
  99. int ret;
  100. if (mutex_lock_interruptible(&state->i2c_buffer_lock) < 0) {
  101. dprintk("could not acquire lock");
  102. return -EINVAL;
  103. }
  104. state->i2c_write_buffer[0] = (reg >> 8) & 0xff;
  105. state->i2c_write_buffer[1] = reg & 0xff;
  106. state->i2c_write_buffer[2] = (val >> 8) & 0xff;
  107. state->i2c_write_buffer[3] = val & 0xff;
  108. memset(&state->msg[0], 0, sizeof(struct i2c_msg));
  109. state->msg[0].addr = state->i2c_addr >> 1;
  110. state->msg[0].flags = 0;
  111. state->msg[0].buf = state->i2c_write_buffer;
  112. state->msg[0].len = 4;
  113. ret = (i2c_transfer(state->i2c_adap, state->msg, 1) != 1 ?
  114. -EREMOTEIO : 0);
  115. mutex_unlock(&state->i2c_buffer_lock);
  116. return ret;
  117. }
  118. static void dib7000p_write_tab(struct dib7000p_state *state, u16 * buf)
  119. {
  120. u16 l = 0, r, *n;
  121. n = buf;
  122. l = *n++;
  123. while (l) {
  124. r = *n++;
  125. do {
  126. dib7000p_write_word(state, r, *n++);
  127. r++;
  128. } while (--l);
  129. l = *n++;
  130. }
  131. }
  132. static int dib7000p_set_output_mode(struct dib7000p_state *state, int mode)
  133. {
  134. int ret = 0;
  135. u16 outreg, fifo_threshold, smo_mode;
  136. outreg = 0;
  137. fifo_threshold = 1792;
  138. smo_mode = (dib7000p_read_word(state, 235) & 0x0050) | (1 << 1);
  139. dprintk("setting output mode for demod %p to %d", &state->demod, mode);
  140. switch (mode) {
  141. case OUTMODE_MPEG2_PAR_GATED_CLK:
  142. outreg = (1 << 10); /* 0x0400 */
  143. break;
  144. case OUTMODE_MPEG2_PAR_CONT_CLK:
  145. outreg = (1 << 10) | (1 << 6); /* 0x0440 */
  146. break;
  147. case OUTMODE_MPEG2_SERIAL:
  148. outreg = (1 << 10) | (2 << 6) | (0 << 1); /* 0x0480 */
  149. break;
  150. case OUTMODE_DIVERSITY:
  151. if (state->cfg.hostbus_diversity)
  152. outreg = (1 << 10) | (4 << 6); /* 0x0500 */
  153. else
  154. outreg = (1 << 11);
  155. break;
  156. case OUTMODE_MPEG2_FIFO:
  157. smo_mode |= (3 << 1);
  158. fifo_threshold = 512;
  159. outreg = (1 << 10) | (5 << 6);
  160. break;
  161. case OUTMODE_ANALOG_ADC:
  162. outreg = (1 << 10) | (3 << 6);
  163. break;
  164. case OUTMODE_HIGH_Z:
  165. outreg = 0;
  166. break;
  167. default:
  168. dprintk("Unhandled output_mode passed to be set for demod %p", &state->demod);
  169. break;
  170. }
  171. if (state->cfg.output_mpeg2_in_188_bytes)
  172. smo_mode |= (1 << 5);
  173. ret |= dib7000p_write_word(state, 235, smo_mode);
  174. ret |= dib7000p_write_word(state, 236, fifo_threshold); /* synchronous fread */
  175. if (state->version != SOC7090)
  176. ret |= dib7000p_write_word(state, 1286, outreg); /* P_Div_active */
  177. return ret;
  178. }
  179. static int dib7000p_set_diversity_in(struct dvb_frontend *demod, int onoff)
  180. {
  181. struct dib7000p_state *state = demod->demodulator_priv;
  182. if (state->div_force_off) {
  183. dprintk("diversity combination deactivated - forced by COFDM parameters");
  184. onoff = 0;
  185. dib7000p_write_word(state, 207, 0);
  186. } else
  187. dib7000p_write_word(state, 207, (state->div_sync_wait << 4) | (1 << 2) | (2 << 0));
  188. state->div_state = (u8) onoff;
  189. if (onoff) {
  190. dib7000p_write_word(state, 204, 6);
  191. dib7000p_write_word(state, 205, 16);
  192. /* P_dvsy_sync_mode = 0, P_dvsy_sync_enable=1, P_dvcb_comb_mode=2 */
  193. } else {
  194. dib7000p_write_word(state, 204, 1);
  195. dib7000p_write_word(state, 205, 0);
  196. }
  197. return 0;
  198. }
  199. static int dib7000p_set_power_mode(struct dib7000p_state *state, enum dib7000p_power_mode mode)
  200. {
  201. /* by default everything is powered off */
  202. u16 reg_774 = 0x3fff, reg_775 = 0xffff, reg_776 = 0x0007, reg_899 = 0x0003, reg_1280 = (0xfe00) | (dib7000p_read_word(state, 1280) & 0x01ff);
  203. /* now, depending on the requested mode, we power on */
  204. switch (mode) {
  205. /* power up everything in the demod */
  206. case DIB7000P_POWER_ALL:
  207. reg_774 = 0x0000;
  208. reg_775 = 0x0000;
  209. reg_776 = 0x0;
  210. reg_899 = 0x0;
  211. if (state->version == SOC7090)
  212. reg_1280 &= 0x001f;
  213. else
  214. reg_1280 &= 0x01ff;
  215. break;
  216. case DIB7000P_POWER_ANALOG_ADC:
  217. /* dem, cfg, iqc, sad, agc */
  218. reg_774 &= ~((1 << 15) | (1 << 14) | (1 << 11) | (1 << 10) | (1 << 9));
  219. /* nud */
  220. reg_776 &= ~((1 << 0));
  221. /* Dout */
  222. if (state->version != SOC7090)
  223. reg_1280 &= ~((1 << 11));
  224. reg_1280 &= ~(1 << 6);
  225. /* fall through wanted to enable the interfaces */
  226. /* just leave power on the control-interfaces: GPIO and (I2C or SDIO) */
  227. case DIB7000P_POWER_INTERFACE_ONLY: /* TODO power up either SDIO or I2C */
  228. if (state->version == SOC7090)
  229. reg_1280 &= ~((1 << 7) | (1 << 5));
  230. else
  231. reg_1280 &= ~((1 << 14) | (1 << 13) | (1 << 12) | (1 << 10));
  232. break;
  233. /* TODO following stuff is just converted from the dib7000-driver - check when is used what */
  234. }
  235. dib7000p_write_word(state, 774, reg_774);
  236. dib7000p_write_word(state, 775, reg_775);
  237. dib7000p_write_word(state, 776, reg_776);
  238. dib7000p_write_word(state, 1280, reg_1280);
  239. if (state->version != SOC7090)
  240. dib7000p_write_word(state, 899, reg_899);
  241. return 0;
  242. }
  243. static void dib7000p_set_adc_state(struct dib7000p_state *state, enum dibx000_adc_states no)
  244. {
  245. u16 reg_908 = 0, reg_909 = 0;
  246. u16 reg;
  247. if (state->version != SOC7090) {
  248. reg_908 = dib7000p_read_word(state, 908);
  249. reg_909 = dib7000p_read_word(state, 909);
  250. }
  251. switch (no) {
  252. case DIBX000_SLOW_ADC_ON:
  253. if (state->version == SOC7090) {
  254. reg = dib7000p_read_word(state, 1925);
  255. dib7000p_write_word(state, 1925, reg | (1 << 4) | (1 << 2)); /* en_slowAdc = 1 & reset_sladc = 1 */
  256. reg = dib7000p_read_word(state, 1925); /* read acces to make it works... strange ... */
  257. msleep(200);
  258. dib7000p_write_word(state, 1925, reg & ~(1 << 4)); /* en_slowAdc = 1 & reset_sladc = 0 */
  259. reg = dib7000p_read_word(state, 72) & ~((0x3 << 14) | (0x3 << 12));
  260. dib7000p_write_word(state, 72, reg | (1 << 14) | (3 << 12) | 524); /* ref = Vin1 => Vbg ; sel = Vin0 or Vin3 ; (Vin2 = Vcm) */
  261. } else {
  262. reg_909 |= (1 << 1) | (1 << 0);
  263. dib7000p_write_word(state, 909, reg_909);
  264. reg_909 &= ~(1 << 1);
  265. }
  266. break;
  267. case DIBX000_SLOW_ADC_OFF:
  268. if (state->version == SOC7090) {
  269. reg = dib7000p_read_word(state, 1925);
  270. dib7000p_write_word(state, 1925, (reg & ~(1 << 2)) | (1 << 4)); /* reset_sladc = 1 en_slowAdc = 0 */
  271. } else
  272. reg_909 |= (1 << 1) | (1 << 0);
  273. break;
  274. case DIBX000_ADC_ON:
  275. reg_908 &= 0x0fff;
  276. reg_909 &= 0x0003;
  277. break;
  278. case DIBX000_ADC_OFF:
  279. reg_908 |= (1 << 14) | (1 << 13) | (1 << 12);
  280. reg_909 |= (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2);
  281. break;
  282. case DIBX000_VBG_ENABLE:
  283. reg_908 &= ~(1 << 15);
  284. break;
  285. case DIBX000_VBG_DISABLE:
  286. reg_908 |= (1 << 15);
  287. break;
  288. default:
  289. break;
  290. }
  291. // dprintk( "908: %x, 909: %x\n", reg_908, reg_909);
  292. reg_909 |= (state->cfg.disable_sample_and_hold & 1) << 4;
  293. reg_908 |= (state->cfg.enable_current_mirror & 1) << 7;
  294. if (state->version != SOC7090) {
  295. dib7000p_write_word(state, 908, reg_908);
  296. dib7000p_write_word(state, 909, reg_909);
  297. }
  298. }
  299. static int dib7000p_set_bandwidth(struct dib7000p_state *state, u32 bw)
  300. {
  301. u32 timf;
  302. // store the current bandwidth for later use
  303. state->current_bandwidth = bw;
  304. if (state->timf == 0) {
  305. dprintk("using default timf");
  306. timf = state->cfg.bw->timf;
  307. } else {
  308. dprintk("using updated timf");
  309. timf = state->timf;
  310. }
  311. timf = timf * (bw / 50) / 160;
  312. dib7000p_write_word(state, 23, (u16) ((timf >> 16) & 0xffff));
  313. dib7000p_write_word(state, 24, (u16) ((timf) & 0xffff));
  314. return 0;
  315. }
  316. static int dib7000p_sad_calib(struct dib7000p_state *state)
  317. {
  318. /* internal */
  319. dib7000p_write_word(state, 73, (0 << 1) | (0 << 0));
  320. if (state->version == SOC7090)
  321. dib7000p_write_word(state, 74, 2048);
  322. else
  323. dib7000p_write_word(state, 74, 776);
  324. /* do the calibration */
  325. dib7000p_write_word(state, 73, (1 << 0));
  326. dib7000p_write_word(state, 73, (0 << 0));
  327. msleep(1);
  328. return 0;
  329. }
  330. static int dib7000p_set_wbd_ref(struct dvb_frontend *demod, u16 value)
  331. {
  332. struct dib7000p_state *state = demod->demodulator_priv;
  333. if (value > 4095)
  334. value = 4095;
  335. state->wbd_ref = value;
  336. return dib7000p_write_word(state, 105, (dib7000p_read_word(state, 105) & 0xf000) | value);
  337. }
  338. static int dib7000p_get_agc_values(struct dvb_frontend *fe,
  339. u16 *agc_global, u16 *agc1, u16 *agc2, u16 *wbd)
  340. {
  341. struct dib7000p_state *state = fe->demodulator_priv;
  342. if (agc_global != NULL)
  343. *agc_global = dib7000p_read_word(state, 394);
  344. if (agc1 != NULL)
  345. *agc1 = dib7000p_read_word(state, 392);
  346. if (agc2 != NULL)
  347. *agc2 = dib7000p_read_word(state, 393);
  348. if (wbd != NULL)
  349. *wbd = dib7000p_read_word(state, 397);
  350. return 0;
  351. }
  352. static int dib7000p_set_agc1_min(struct dvb_frontend *fe, u16 v)
  353. {
  354. struct dib7000p_state *state = fe->demodulator_priv;
  355. return dib7000p_write_word(state, 108, v);
  356. }
  357. static void dib7000p_reset_pll(struct dib7000p_state *state)
  358. {
  359. struct dibx000_bandwidth_config *bw = &state->cfg.bw[0];
  360. u16 clk_cfg0;
  361. if (state->version == SOC7090) {
  362. dib7000p_write_word(state, 1856, (!bw->pll_reset << 13) | (bw->pll_range << 12) | (bw->pll_ratio << 6) | (bw->pll_prediv));
  363. while (((dib7000p_read_word(state, 1856) >> 15) & 0x1) != 1)
  364. ;
  365. dib7000p_write_word(state, 1857, dib7000p_read_word(state, 1857) | (!bw->pll_bypass << 15));
  366. } else {
  367. /* force PLL bypass */
  368. clk_cfg0 = (1 << 15) | ((bw->pll_ratio & 0x3f) << 9) |
  369. (bw->modulo << 7) | (bw->ADClkSrc << 6) | (bw->IO_CLK_en_core << 5) | (bw->bypclk_div << 2) | (bw->enable_refdiv << 1) | (0 << 0);
  370. dib7000p_write_word(state, 900, clk_cfg0);
  371. /* P_pll_cfg */
  372. dib7000p_write_word(state, 903, (bw->pll_prediv << 5) | (((bw->pll_ratio >> 6) & 0x3) << 3) | (bw->pll_range << 1) | bw->pll_reset);
  373. clk_cfg0 = (bw->pll_bypass << 15) | (clk_cfg0 & 0x7fff);
  374. dib7000p_write_word(state, 900, clk_cfg0);
  375. }
  376. dib7000p_write_word(state, 18, (u16) (((bw->internal * 1000) >> 16) & 0xffff));
  377. dib7000p_write_word(state, 19, (u16) ((bw->internal * 1000) & 0xffff));
  378. dib7000p_write_word(state, 21, (u16) ((bw->ifreq >> 16) & 0xffff));
  379. dib7000p_write_word(state, 22, (u16) ((bw->ifreq) & 0xffff));
  380. dib7000p_write_word(state, 72, bw->sad_cfg);
  381. }
  382. static u32 dib7000p_get_internal_freq(struct dib7000p_state *state)
  383. {
  384. u32 internal = (u32) dib7000p_read_word(state, 18) << 16;
  385. internal |= (u32) dib7000p_read_word(state, 19);
  386. internal /= 1000;
  387. return internal;
  388. }
  389. static int dib7000p_update_pll(struct dvb_frontend *fe, struct dibx000_bandwidth_config *bw)
  390. {
  391. struct dib7000p_state *state = fe->demodulator_priv;
  392. u16 reg_1857, reg_1856 = dib7000p_read_word(state, 1856);
  393. u8 loopdiv, prediv;
  394. u32 internal, xtal;
  395. /* get back old values */
  396. prediv = reg_1856 & 0x3f;
  397. loopdiv = (reg_1856 >> 6) & 0x3f;
  398. if ((bw != NULL) && (bw->pll_prediv != prediv || bw->pll_ratio != loopdiv)) {
  399. dprintk("Updating pll (prediv: old = %d new = %d ; loopdiv : old = %d new = %d)", prediv, bw->pll_prediv, loopdiv, bw->pll_ratio);
  400. reg_1856 &= 0xf000;
  401. reg_1857 = dib7000p_read_word(state, 1857);
  402. dib7000p_write_word(state, 1857, reg_1857 & ~(1 << 15));
  403. dib7000p_write_word(state, 1856, reg_1856 | ((bw->pll_ratio & 0x3f) << 6) | (bw->pll_prediv & 0x3f));
  404. /* write new system clk into P_sec_len */
  405. internal = dib7000p_get_internal_freq(state);
  406. xtal = (internal / loopdiv) * prediv;
  407. internal = 1000 * (xtal / bw->pll_prediv) * bw->pll_ratio; /* new internal */
  408. dib7000p_write_word(state, 18, (u16) ((internal >> 16) & 0xffff));
  409. dib7000p_write_word(state, 19, (u16) (internal & 0xffff));
  410. dib7000p_write_word(state, 1857, reg_1857 | (1 << 15));
  411. while (((dib7000p_read_word(state, 1856) >> 15) & 0x1) != 1)
  412. dprintk("Waiting for PLL to lock");
  413. return 0;
  414. }
  415. return -EIO;
  416. }
  417. static int dib7000p_reset_gpio(struct dib7000p_state *st)
  418. {
  419. /* reset the GPIOs */
  420. dprintk("gpio dir: %x: val: %x, pwm_pos: %x", st->gpio_dir, st->gpio_val, st->cfg.gpio_pwm_pos);
  421. dib7000p_write_word(st, 1029, st->gpio_dir);
  422. dib7000p_write_word(st, 1030, st->gpio_val);
  423. /* TODO 1031 is P_gpio_od */
  424. dib7000p_write_word(st, 1032, st->cfg.gpio_pwm_pos);
  425. dib7000p_write_word(st, 1037, st->cfg.pwm_freq_div);
  426. return 0;
  427. }
  428. static int dib7000p_cfg_gpio(struct dib7000p_state *st, u8 num, u8 dir, u8 val)
  429. {
  430. st->gpio_dir = dib7000p_read_word(st, 1029);
  431. st->gpio_dir &= ~(1 << num); /* reset the direction bit */
  432. st->gpio_dir |= (dir & 0x1) << num; /* set the new direction */
  433. dib7000p_write_word(st, 1029, st->gpio_dir);
  434. st->gpio_val = dib7000p_read_word(st, 1030);
  435. st->gpio_val &= ~(1 << num); /* reset the direction bit */
  436. st->gpio_val |= (val & 0x01) << num; /* set the new value */
  437. dib7000p_write_word(st, 1030, st->gpio_val);
  438. return 0;
  439. }
  440. static int dib7000p_set_gpio(struct dvb_frontend *demod, u8 num, u8 dir, u8 val)
  441. {
  442. struct dib7000p_state *state = demod->demodulator_priv;
  443. return dib7000p_cfg_gpio(state, num, dir, val);
  444. }
  445. static u16 dib7000p_defaults[] = {
  446. // auto search configuration
  447. 3, 2,
  448. 0x0004,
  449. (1<<3)|(1<<11)|(1<<12)|(1<<13),
  450. 0x0814, /* Equal Lock */
  451. 12, 6,
  452. 0x001b,
  453. 0x7740,
  454. 0x005b,
  455. 0x8d80,
  456. 0x01c9,
  457. 0xc380,
  458. 0x0000,
  459. 0x0080,
  460. 0x0000,
  461. 0x0090,
  462. 0x0001,
  463. 0xd4c0,
  464. 1, 26,
  465. 0x6680,
  466. /* set ADC level to -16 */
  467. 11, 79,
  468. (1 << 13) - 825 - 117,
  469. (1 << 13) - 837 - 117,
  470. (1 << 13) - 811 - 117,
  471. (1 << 13) - 766 - 117,
  472. (1 << 13) - 737 - 117,
  473. (1 << 13) - 693 - 117,
  474. (1 << 13) - 648 - 117,
  475. (1 << 13) - 619 - 117,
  476. (1 << 13) - 575 - 117,
  477. (1 << 13) - 531 - 117,
  478. (1 << 13) - 501 - 117,
  479. 1, 142,
  480. 0x0410,
  481. /* disable power smoothing */
  482. 8, 145,
  483. 0,
  484. 0,
  485. 0,
  486. 0,
  487. 0,
  488. 0,
  489. 0,
  490. 0,
  491. 1, 154,
  492. 1 << 13,
  493. 1, 168,
  494. 0x0ccd,
  495. 1, 183,
  496. 0x200f,
  497. 1, 212,
  498. 0x169,
  499. 5, 187,
  500. 0x023d,
  501. 0x00a4,
  502. 0x00a4,
  503. 0x7ff0,
  504. 0x3ccc,
  505. 1, 198,
  506. 0x800,
  507. 1, 222,
  508. 0x0010,
  509. 1, 235,
  510. 0x0062,
  511. 0,
  512. };
  513. static void dib7000p_reset_stats(struct dvb_frontend *fe);
  514. static int dib7000p_demod_reset(struct dib7000p_state *state)
  515. {
  516. dib7000p_set_power_mode(state, DIB7000P_POWER_ALL);
  517. if (state->version == SOC7090)
  518. dibx000_reset_i2c_master(&state->i2c_master);
  519. dib7000p_set_adc_state(state, DIBX000_VBG_ENABLE);
  520. /* restart all parts */
  521. dib7000p_write_word(state, 770, 0xffff);
  522. dib7000p_write_word(state, 771, 0xffff);
  523. dib7000p_write_word(state, 772, 0x001f);
  524. dib7000p_write_word(state, 1280, 0x001f - ((1 << 4) | (1 << 3)));
  525. dib7000p_write_word(state, 770, 0);
  526. dib7000p_write_word(state, 771, 0);
  527. dib7000p_write_word(state, 772, 0);
  528. dib7000p_write_word(state, 1280, 0);
  529. if (state->version != SOC7090) {
  530. dib7000p_write_word(state, 898, 0x0003);
  531. dib7000p_write_word(state, 898, 0);
  532. }
  533. /* default */
  534. dib7000p_reset_pll(state);
  535. if (dib7000p_reset_gpio(state) != 0)
  536. dprintk("GPIO reset was not successful.");
  537. if (state->version == SOC7090) {
  538. dib7000p_write_word(state, 899, 0);
  539. /* impulse noise */
  540. dib7000p_write_word(state, 42, (1<<5) | 3); /* P_iqc_thsat_ipc = 1 ; P_iqc_win2 = 3 */
  541. dib7000p_write_word(state, 43, 0x2d4); /*-300 fag P_iqc_dect_min = -280 */
  542. dib7000p_write_word(state, 44, 300); /* 300 fag P_iqc_dect_min = +280 */
  543. dib7000p_write_word(state, 273, (0<<6) | 30);
  544. }
  545. if (dib7000p_set_output_mode(state, OUTMODE_HIGH_Z) != 0)
  546. dprintk("OUTPUT_MODE could not be reset.");
  547. dib7000p_set_adc_state(state, DIBX000_SLOW_ADC_ON);
  548. dib7000p_sad_calib(state);
  549. dib7000p_set_adc_state(state, DIBX000_SLOW_ADC_OFF);
  550. /* unforce divstr regardless whether i2c enumeration was done or not */
  551. dib7000p_write_word(state, 1285, dib7000p_read_word(state, 1285) & ~(1 << 1));
  552. dib7000p_set_bandwidth(state, 8000);
  553. if (state->version == SOC7090) {
  554. dib7000p_write_word(state, 36, 0x0755);/* P_iqc_impnc_on =1 & P_iqc_corr_inh = 1 for impulsive noise */
  555. } else {
  556. if (state->cfg.tuner_is_baseband)
  557. dib7000p_write_word(state, 36, 0x0755);
  558. else
  559. dib7000p_write_word(state, 36, 0x1f55);
  560. }
  561. dib7000p_write_tab(state, dib7000p_defaults);
  562. if (state->version != SOC7090) {
  563. dib7000p_write_word(state, 901, 0x0006);
  564. dib7000p_write_word(state, 902, (3 << 10) | (1 << 6));
  565. dib7000p_write_word(state, 905, 0x2c8e);
  566. }
  567. dib7000p_set_power_mode(state, DIB7000P_POWER_INTERFACE_ONLY);
  568. return 0;
  569. }
  570. static void dib7000p_pll_clk_cfg(struct dib7000p_state *state)
  571. {
  572. u16 tmp = 0;
  573. tmp = dib7000p_read_word(state, 903);
  574. dib7000p_write_word(state, 903, (tmp | 0x1));
  575. tmp = dib7000p_read_word(state, 900);
  576. dib7000p_write_word(state, 900, (tmp & 0x7fff) | (1 << 6));
  577. }
  578. static void dib7000p_restart_agc(struct dib7000p_state *state)
  579. {
  580. // P_restart_iqc & P_restart_agc
  581. dib7000p_write_word(state, 770, (1 << 11) | (1 << 9));
  582. dib7000p_write_word(state, 770, 0x0000);
  583. }
  584. static int dib7000p_update_lna(struct dib7000p_state *state)
  585. {
  586. u16 dyn_gain;
  587. if (state->cfg.update_lna) {
  588. dyn_gain = dib7000p_read_word(state, 394);
  589. if (state->cfg.update_lna(&state->demod, dyn_gain)) {
  590. dib7000p_restart_agc(state);
  591. return 1;
  592. }
  593. }
  594. return 0;
  595. }
  596. static int dib7000p_set_agc_config(struct dib7000p_state *state, u8 band)
  597. {
  598. struct dibx000_agc_config *agc = NULL;
  599. int i;
  600. if (state->current_band == band && state->current_agc != NULL)
  601. return 0;
  602. state->current_band = band;
  603. for (i = 0; i < state->cfg.agc_config_count; i++)
  604. if (state->cfg.agc[i].band_caps & band) {
  605. agc = &state->cfg.agc[i];
  606. break;
  607. }
  608. if (agc == NULL) {
  609. dprintk("no valid AGC configuration found for band 0x%02x", band);
  610. return -EINVAL;
  611. }
  612. state->current_agc = agc;
  613. /* AGC */
  614. dib7000p_write_word(state, 75, agc->setup);
  615. dib7000p_write_word(state, 76, agc->inv_gain);
  616. dib7000p_write_word(state, 77, agc->time_stabiliz);
  617. dib7000p_write_word(state, 100, (agc->alpha_level << 12) | agc->thlock);
  618. // Demod AGC loop configuration
  619. dib7000p_write_word(state, 101, (agc->alpha_mant << 5) | agc->alpha_exp);
  620. dib7000p_write_word(state, 102, (agc->beta_mant << 6) | agc->beta_exp);
  621. /* AGC continued */
  622. dprintk("WBD: ref: %d, sel: %d, active: %d, alpha: %d",
  623. state->wbd_ref != 0 ? state->wbd_ref : agc->wbd_ref, agc->wbd_sel, !agc->perform_agc_softsplit, agc->wbd_sel);
  624. if (state->wbd_ref != 0)
  625. dib7000p_write_word(state, 105, (agc->wbd_inv << 12) | state->wbd_ref);
  626. else
  627. dib7000p_write_word(state, 105, (agc->wbd_inv << 12) | agc->wbd_ref);
  628. dib7000p_write_word(state, 106, (agc->wbd_sel << 13) | (agc->wbd_alpha << 9) | (agc->perform_agc_softsplit << 8));
  629. dib7000p_write_word(state, 107, agc->agc1_max);
  630. dib7000p_write_word(state, 108, agc->agc1_min);
  631. dib7000p_write_word(state, 109, agc->agc2_max);
  632. dib7000p_write_word(state, 110, agc->agc2_min);
  633. dib7000p_write_word(state, 111, (agc->agc1_pt1 << 8) | agc->agc1_pt2);
  634. dib7000p_write_word(state, 112, agc->agc1_pt3);
  635. dib7000p_write_word(state, 113, (agc->agc1_slope1 << 8) | agc->agc1_slope2);
  636. dib7000p_write_word(state, 114, (agc->agc2_pt1 << 8) | agc->agc2_pt2);
  637. dib7000p_write_word(state, 115, (agc->agc2_slope1 << 8) | agc->agc2_slope2);
  638. return 0;
  639. }
  640. static void dib7000p_set_dds(struct dib7000p_state *state, s32 offset_khz)
  641. {
  642. u32 internal = dib7000p_get_internal_freq(state);
  643. s32 unit_khz_dds_val = 67108864 / (internal); /* 2**26 / Fsampling is the unit 1KHz offset */
  644. u32 abs_offset_khz = ABS(offset_khz);
  645. u32 dds = state->cfg.bw->ifreq & 0x1ffffff;
  646. u8 invert = !!(state->cfg.bw->ifreq & (1 << 25));
  647. dprintk("setting a frequency offset of %dkHz internal freq = %d invert = %d", offset_khz, internal, invert);
  648. if (offset_khz < 0)
  649. unit_khz_dds_val *= -1;
  650. /* IF tuner */
  651. if (invert)
  652. dds -= (abs_offset_khz * unit_khz_dds_val); /* /100 because of /100 on the unit_khz_dds_val line calc for better accuracy */
  653. else
  654. dds += (abs_offset_khz * unit_khz_dds_val);
  655. if (abs_offset_khz <= (internal / 2)) { /* Max dds offset is the half of the demod freq */
  656. dib7000p_write_word(state, 21, (u16) (((dds >> 16) & 0x1ff) | (0 << 10) | (invert << 9)));
  657. dib7000p_write_word(state, 22, (u16) (dds & 0xffff));
  658. }
  659. }
  660. static int dib7000p_agc_startup(struct dvb_frontend *demod)
  661. {
  662. struct dtv_frontend_properties *ch = &demod->dtv_property_cache;
  663. struct dib7000p_state *state = demod->demodulator_priv;
  664. int ret = -1;
  665. u8 *agc_state = &state->agc_state;
  666. u8 agc_split;
  667. u16 reg;
  668. u32 upd_demod_gain_period = 0x1000;
  669. s32 frequency_offset = 0;
  670. switch (state->agc_state) {
  671. case 0:
  672. dib7000p_set_power_mode(state, DIB7000P_POWER_ALL);
  673. if (state->version == SOC7090) {
  674. reg = dib7000p_read_word(state, 0x79b) & 0xff00;
  675. dib7000p_write_word(state, 0x79a, upd_demod_gain_period & 0xFFFF); /* lsb */
  676. dib7000p_write_word(state, 0x79b, reg | (1 << 14) | ((upd_demod_gain_period >> 16) & 0xFF));
  677. /* enable adc i & q */
  678. reg = dib7000p_read_word(state, 0x780);
  679. dib7000p_write_word(state, 0x780, (reg | (0x3)) & (~(1 << 7)));
  680. } else {
  681. dib7000p_set_adc_state(state, DIBX000_ADC_ON);
  682. dib7000p_pll_clk_cfg(state);
  683. }
  684. if (dib7000p_set_agc_config(state, BAND_OF_FREQUENCY(ch->frequency / 1000)) != 0)
  685. return -1;
  686. if (demod->ops.tuner_ops.get_frequency) {
  687. u32 frequency_tuner;
  688. demod->ops.tuner_ops.get_frequency(demod, &frequency_tuner);
  689. frequency_offset = (s32)frequency_tuner / 1000 - ch->frequency / 1000;
  690. }
  691. dib7000p_set_dds(state, frequency_offset);
  692. ret = 7;
  693. (*agc_state)++;
  694. break;
  695. case 1:
  696. if (state->cfg.agc_control)
  697. state->cfg.agc_control(&state->demod, 1);
  698. dib7000p_write_word(state, 78, 32768);
  699. if (!state->current_agc->perform_agc_softsplit) {
  700. /* we are using the wbd - so slow AGC startup */
  701. /* force 0 split on WBD and restart AGC */
  702. dib7000p_write_word(state, 106, (state->current_agc->wbd_sel << 13) | (state->current_agc->wbd_alpha << 9) | (1 << 8));
  703. (*agc_state)++;
  704. ret = 5;
  705. } else {
  706. /* default AGC startup */
  707. (*agc_state) = 4;
  708. /* wait AGC rough lock time */
  709. ret = 7;
  710. }
  711. dib7000p_restart_agc(state);
  712. break;
  713. case 2: /* fast split search path after 5sec */
  714. dib7000p_write_word(state, 75, state->current_agc->setup | (1 << 4)); /* freeze AGC loop */
  715. dib7000p_write_word(state, 106, (state->current_agc->wbd_sel << 13) | (2 << 9) | (0 << 8)); /* fast split search 0.25kHz */
  716. (*agc_state)++;
  717. ret = 14;
  718. break;
  719. case 3: /* split search ended */
  720. agc_split = (u8) dib7000p_read_word(state, 396); /* store the split value for the next time */
  721. dib7000p_write_word(state, 78, dib7000p_read_word(state, 394)); /* set AGC gain start value */
  722. dib7000p_write_word(state, 75, state->current_agc->setup); /* std AGC loop */
  723. dib7000p_write_word(state, 106, (state->current_agc->wbd_sel << 13) | (state->current_agc->wbd_alpha << 9) | agc_split); /* standard split search */
  724. dib7000p_restart_agc(state);
  725. dprintk("SPLIT %p: %hd", demod, agc_split);
  726. (*agc_state)++;
  727. ret = 5;
  728. break;
  729. case 4: /* LNA startup */
  730. ret = 7;
  731. if (dib7000p_update_lna(state))
  732. ret = 5;
  733. else
  734. (*agc_state)++;
  735. break;
  736. case 5:
  737. if (state->cfg.agc_control)
  738. state->cfg.agc_control(&state->demod, 0);
  739. (*agc_state)++;
  740. break;
  741. default:
  742. break;
  743. }
  744. return ret;
  745. }
  746. static void dib7000p_update_timf(struct dib7000p_state *state)
  747. {
  748. u32 timf = (dib7000p_read_word(state, 427) << 16) | dib7000p_read_word(state, 428);
  749. state->timf = timf * 160 / (state->current_bandwidth / 50);
  750. dib7000p_write_word(state, 23, (u16) (timf >> 16));
  751. dib7000p_write_word(state, 24, (u16) (timf & 0xffff));
  752. dprintk("updated timf_frequency: %d (default: %d)", state->timf, state->cfg.bw->timf);
  753. }
  754. static u32 dib7000p_ctrl_timf(struct dvb_frontend *fe, u8 op, u32 timf)
  755. {
  756. struct dib7000p_state *state = fe->demodulator_priv;
  757. switch (op) {
  758. case DEMOD_TIMF_SET:
  759. state->timf = timf;
  760. break;
  761. case DEMOD_TIMF_UPDATE:
  762. dib7000p_update_timf(state);
  763. break;
  764. case DEMOD_TIMF_GET:
  765. break;
  766. }
  767. dib7000p_set_bandwidth(state, state->current_bandwidth);
  768. return state->timf;
  769. }
  770. static void dib7000p_set_channel(struct dib7000p_state *state,
  771. struct dtv_frontend_properties *ch, u8 seq)
  772. {
  773. u16 value, est[4];
  774. dib7000p_set_bandwidth(state, BANDWIDTH_TO_KHZ(ch->bandwidth_hz));
  775. /* nfft, guard, qam, alpha */
  776. value = 0;
  777. switch (ch->transmission_mode) {
  778. case TRANSMISSION_MODE_2K:
  779. value |= (0 << 7);
  780. break;
  781. case TRANSMISSION_MODE_4K:
  782. value |= (2 << 7);
  783. break;
  784. default:
  785. case TRANSMISSION_MODE_8K:
  786. value |= (1 << 7);
  787. break;
  788. }
  789. switch (ch->guard_interval) {
  790. case GUARD_INTERVAL_1_32:
  791. value |= (0 << 5);
  792. break;
  793. case GUARD_INTERVAL_1_16:
  794. value |= (1 << 5);
  795. break;
  796. case GUARD_INTERVAL_1_4:
  797. value |= (3 << 5);
  798. break;
  799. default:
  800. case GUARD_INTERVAL_1_8:
  801. value |= (2 << 5);
  802. break;
  803. }
  804. switch (ch->modulation) {
  805. case QPSK:
  806. value |= (0 << 3);
  807. break;
  808. case QAM_16:
  809. value |= (1 << 3);
  810. break;
  811. default:
  812. case QAM_64:
  813. value |= (2 << 3);
  814. break;
  815. }
  816. switch (HIERARCHY_1) {
  817. case HIERARCHY_2:
  818. value |= 2;
  819. break;
  820. case HIERARCHY_4:
  821. value |= 4;
  822. break;
  823. default:
  824. case HIERARCHY_1:
  825. value |= 1;
  826. break;
  827. }
  828. dib7000p_write_word(state, 0, value);
  829. dib7000p_write_word(state, 5, (seq << 4) | 1); /* do not force tps, search list 0 */
  830. /* P_dintl_native, P_dintlv_inv, P_hrch, P_code_rate, P_select_hp */
  831. value = 0;
  832. if (1 != 0)
  833. value |= (1 << 6);
  834. if (ch->hierarchy == 1)
  835. value |= (1 << 4);
  836. if (1 == 1)
  837. value |= 1;
  838. switch ((ch->hierarchy == 0 || 1 == 1) ? ch->code_rate_HP : ch->code_rate_LP) {
  839. case FEC_2_3:
  840. value |= (2 << 1);
  841. break;
  842. case FEC_3_4:
  843. value |= (3 << 1);
  844. break;
  845. case FEC_5_6:
  846. value |= (5 << 1);
  847. break;
  848. case FEC_7_8:
  849. value |= (7 << 1);
  850. break;
  851. default:
  852. case FEC_1_2:
  853. value |= (1 << 1);
  854. break;
  855. }
  856. dib7000p_write_word(state, 208, value);
  857. /* offset loop parameters */
  858. dib7000p_write_word(state, 26, 0x6680);
  859. dib7000p_write_word(state, 32, 0x0003);
  860. dib7000p_write_word(state, 29, 0x1273);
  861. dib7000p_write_word(state, 33, 0x0005);
  862. /* P_dvsy_sync_wait */
  863. switch (ch->transmission_mode) {
  864. case TRANSMISSION_MODE_8K:
  865. value = 256;
  866. break;
  867. case TRANSMISSION_MODE_4K:
  868. value = 128;
  869. break;
  870. case TRANSMISSION_MODE_2K:
  871. default:
  872. value = 64;
  873. break;
  874. }
  875. switch (ch->guard_interval) {
  876. case GUARD_INTERVAL_1_16:
  877. value *= 2;
  878. break;
  879. case GUARD_INTERVAL_1_8:
  880. value *= 4;
  881. break;
  882. case GUARD_INTERVAL_1_4:
  883. value *= 8;
  884. break;
  885. default:
  886. case GUARD_INTERVAL_1_32:
  887. value *= 1;
  888. break;
  889. }
  890. if (state->cfg.diversity_delay == 0)
  891. state->div_sync_wait = (value * 3) / 2 + 48;
  892. else
  893. state->div_sync_wait = (value * 3) / 2 + state->cfg.diversity_delay;
  894. /* deactive the possibility of diversity reception if extended interleaver */
  895. state->div_force_off = !1 && ch->transmission_mode != TRANSMISSION_MODE_8K;
  896. dib7000p_set_diversity_in(&state->demod, state->div_state);
  897. /* channel estimation fine configuration */
  898. switch (ch->modulation) {
  899. case QAM_64:
  900. est[0] = 0x0148; /* P_adp_regul_cnt 0.04 */
  901. est[1] = 0xfff0; /* P_adp_noise_cnt -0.002 */
  902. est[2] = 0x00a4; /* P_adp_regul_ext 0.02 */
  903. est[3] = 0xfff8; /* P_adp_noise_ext -0.001 */
  904. break;
  905. case QAM_16:
  906. est[0] = 0x023d; /* P_adp_regul_cnt 0.07 */
  907. est[1] = 0xffdf; /* P_adp_noise_cnt -0.004 */
  908. est[2] = 0x00a4; /* P_adp_regul_ext 0.02 */
  909. est[3] = 0xfff0; /* P_adp_noise_ext -0.002 */
  910. break;
  911. default:
  912. est[0] = 0x099a; /* P_adp_regul_cnt 0.3 */
  913. est[1] = 0xffae; /* P_adp_noise_cnt -0.01 */
  914. est[2] = 0x0333; /* P_adp_regul_ext 0.1 */
  915. est[3] = 0xfff8; /* P_adp_noise_ext -0.002 */
  916. break;
  917. }
  918. for (value = 0; value < 4; value++)
  919. dib7000p_write_word(state, 187 + value, est[value]);
  920. }
  921. static int dib7000p_autosearch_start(struct dvb_frontend *demod)
  922. {
  923. struct dtv_frontend_properties *ch = &demod->dtv_property_cache;
  924. struct dib7000p_state *state = demod->demodulator_priv;
  925. struct dtv_frontend_properties schan;
  926. u32 value, factor;
  927. u32 internal = dib7000p_get_internal_freq(state);
  928. schan = *ch;
  929. schan.modulation = QAM_64;
  930. schan.guard_interval = GUARD_INTERVAL_1_32;
  931. schan.transmission_mode = TRANSMISSION_MODE_8K;
  932. schan.code_rate_HP = FEC_2_3;
  933. schan.code_rate_LP = FEC_3_4;
  934. schan.hierarchy = 0;
  935. dib7000p_set_channel(state, &schan, 7);
  936. factor = BANDWIDTH_TO_KHZ(ch->bandwidth_hz);
  937. if (factor >= 5000) {
  938. if (state->version == SOC7090)
  939. factor = 2;
  940. else
  941. factor = 1;
  942. } else
  943. factor = 6;
  944. value = 30 * internal * factor;
  945. dib7000p_write_word(state, 6, (u16) ((value >> 16) & 0xffff));
  946. dib7000p_write_word(state, 7, (u16) (value & 0xffff));
  947. value = 100 * internal * factor;
  948. dib7000p_write_word(state, 8, (u16) ((value >> 16) & 0xffff));
  949. dib7000p_write_word(state, 9, (u16) (value & 0xffff));
  950. value = 500 * internal * factor;
  951. dib7000p_write_word(state, 10, (u16) ((value >> 16) & 0xffff));
  952. dib7000p_write_word(state, 11, (u16) (value & 0xffff));
  953. value = dib7000p_read_word(state, 0);
  954. dib7000p_write_word(state, 0, (u16) ((1 << 9) | value));
  955. dib7000p_read_word(state, 1284);
  956. dib7000p_write_word(state, 0, (u16) value);
  957. return 0;
  958. }
  959. static int dib7000p_autosearch_is_irq(struct dvb_frontend *demod)
  960. {
  961. struct dib7000p_state *state = demod->demodulator_priv;
  962. u16 irq_pending = dib7000p_read_word(state, 1284);
  963. if (irq_pending & 0x1)
  964. return 1;
  965. if (irq_pending & 0x2)
  966. return 2;
  967. return 0;
  968. }
  969. static void dib7000p_spur_protect(struct dib7000p_state *state, u32 rf_khz, u32 bw)
  970. {
  971. static s16 notch[] = { 16143, 14402, 12238, 9713, 6902, 3888, 759, -2392 };
  972. static u8 sine[] = { 0, 2, 3, 5, 6, 8, 9, 11, 13, 14, 16, 17, 19, 20, 22,
  973. 24, 25, 27, 28, 30, 31, 33, 34, 36, 38, 39, 41, 42, 44, 45, 47, 48, 50, 51,
  974. 53, 55, 56, 58, 59, 61, 62, 64, 65, 67, 68, 70, 71, 73, 74, 76, 77, 79, 80,
  975. 82, 83, 85, 86, 88, 89, 91, 92, 94, 95, 97, 98, 99, 101, 102, 104, 105,
  976. 107, 108, 109, 111, 112, 114, 115, 117, 118, 119, 121, 122, 123, 125, 126,
  977. 128, 129, 130, 132, 133, 134, 136, 137, 138, 140, 141, 142, 144, 145, 146,
  978. 147, 149, 150, 151, 152, 154, 155, 156, 157, 159, 160, 161, 162, 164, 165,
  979. 166, 167, 168, 170, 171, 172, 173, 174, 175, 177, 178, 179, 180, 181, 182,
  980. 183, 184, 185, 186, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198,
  981. 199, 200, 201, 202, 203, 204, 205, 206, 207, 207, 208, 209, 210, 211, 212,
  982. 213, 214, 215, 215, 216, 217, 218, 219, 220, 220, 221, 222, 223, 224, 224,
  983. 225, 226, 227, 227, 228, 229, 229, 230, 231, 231, 232, 233, 233, 234, 235,
  984. 235, 236, 237, 237, 238, 238, 239, 239, 240, 241, 241, 242, 242, 243, 243,
  985. 244, 244, 245, 245, 245, 246, 246, 247, 247, 248, 248, 248, 249, 249, 249,
  986. 250, 250, 250, 251, 251, 251, 252, 252, 252, 252, 253, 253, 253, 253, 254,
  987. 254, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
  988. 255, 255, 255, 255, 255, 255
  989. };
  990. u32 xtal = state->cfg.bw->xtal_hz / 1000;
  991. int f_rel = DIV_ROUND_CLOSEST(rf_khz, xtal) * xtal - rf_khz;
  992. int k;
  993. int coef_re[8], coef_im[8];
  994. int bw_khz = bw;
  995. u32 pha;
  996. dprintk("relative position of the Spur: %dk (RF: %dk, XTAL: %dk)", f_rel, rf_khz, xtal);
  997. if (f_rel < -bw_khz / 2 || f_rel > bw_khz / 2)
  998. return;
  999. bw_khz /= 100;
  1000. dib7000p_write_word(state, 142, 0x0610);
  1001. for (k = 0; k < 8; k++) {
  1002. pha = ((f_rel * (k + 1) * 112 * 80 / bw_khz) / 1000) & 0x3ff;
  1003. if (pha == 0) {
  1004. coef_re[k] = 256;
  1005. coef_im[k] = 0;
  1006. } else if (pha < 256) {
  1007. coef_re[k] = sine[256 - (pha & 0xff)];
  1008. coef_im[k] = sine[pha & 0xff];
  1009. } else if (pha == 256) {
  1010. coef_re[k] = 0;
  1011. coef_im[k] = 256;
  1012. } else if (pha < 512) {
  1013. coef_re[k] = -sine[pha & 0xff];
  1014. coef_im[k] = sine[256 - (pha & 0xff)];
  1015. } else if (pha == 512) {
  1016. coef_re[k] = -256;
  1017. coef_im[k] = 0;
  1018. } else if (pha < 768) {
  1019. coef_re[k] = -sine[256 - (pha & 0xff)];
  1020. coef_im[k] = -sine[pha & 0xff];
  1021. } else if (pha == 768) {
  1022. coef_re[k] = 0;
  1023. coef_im[k] = -256;
  1024. } else {
  1025. coef_re[k] = sine[pha & 0xff];
  1026. coef_im[k] = -sine[256 - (pha & 0xff)];
  1027. }
  1028. coef_re[k] *= notch[k];
  1029. coef_re[k] += (1 << 14);
  1030. if (coef_re[k] >= (1 << 24))
  1031. coef_re[k] = (1 << 24) - 1;
  1032. coef_re[k] /= (1 << 15);
  1033. coef_im[k] *= notch[k];
  1034. coef_im[k] += (1 << 14);
  1035. if (coef_im[k] >= (1 << 24))
  1036. coef_im[k] = (1 << 24) - 1;
  1037. coef_im[k] /= (1 << 15);
  1038. dprintk("PALF COEF: %d re: %d im: %d", k, coef_re[k], coef_im[k]);
  1039. dib7000p_write_word(state, 143, (0 << 14) | (k << 10) | (coef_re[k] & 0x3ff));
  1040. dib7000p_write_word(state, 144, coef_im[k] & 0x3ff);
  1041. dib7000p_write_word(state, 143, (1 << 14) | (k << 10) | (coef_re[k] & 0x3ff));
  1042. }
  1043. dib7000p_write_word(state, 143, 0);
  1044. }
  1045. static int dib7000p_tune(struct dvb_frontend *demod)
  1046. {
  1047. struct dtv_frontend_properties *ch = &demod->dtv_property_cache;
  1048. struct dib7000p_state *state = demod->demodulator_priv;
  1049. u16 tmp = 0;
  1050. if (ch != NULL)
  1051. dib7000p_set_channel(state, ch, 0);
  1052. else
  1053. return -EINVAL;
  1054. // restart demod
  1055. dib7000p_write_word(state, 770, 0x4000);
  1056. dib7000p_write_word(state, 770, 0x0000);
  1057. msleep(45);
  1058. /* P_ctrl_inh_cor=0, P_ctrl_alpha_cor=4, P_ctrl_inh_isi=0, P_ctrl_alpha_isi=3, P_ctrl_inh_cor4=1, P_ctrl_alpha_cor4=3 */
  1059. tmp = (0 << 14) | (4 << 10) | (0 << 9) | (3 << 5) | (1 << 4) | (0x3);
  1060. if (state->sfn_workaround_active) {
  1061. dprintk("SFN workaround is active");
  1062. tmp |= (1 << 9);
  1063. dib7000p_write_word(state, 166, 0x4000);
  1064. } else {
  1065. dib7000p_write_word(state, 166, 0x0000);
  1066. }
  1067. dib7000p_write_word(state, 29, tmp);
  1068. // never achieved a lock with that bandwidth so far - wait for osc-freq to update
  1069. if (state->timf == 0)
  1070. msleep(200);
  1071. /* offset loop parameters */
  1072. /* P_timf_alpha, P_corm_alpha=6, P_corm_thres=0x80 */
  1073. tmp = (6 << 8) | 0x80;
  1074. switch (ch->transmission_mode) {
  1075. case TRANSMISSION_MODE_2K:
  1076. tmp |= (2 << 12);
  1077. break;
  1078. case TRANSMISSION_MODE_4K:
  1079. tmp |= (3 << 12);
  1080. break;
  1081. default:
  1082. case TRANSMISSION_MODE_8K:
  1083. tmp |= (4 << 12);
  1084. break;
  1085. }
  1086. dib7000p_write_word(state, 26, tmp); /* timf_a(6xxx) */
  1087. /* P_ctrl_freeze_pha_shift=0, P_ctrl_pha_off_max */
  1088. tmp = (0 << 4);
  1089. switch (ch->transmission_mode) {
  1090. case TRANSMISSION_MODE_2K:
  1091. tmp |= 0x6;
  1092. break;
  1093. case TRANSMISSION_MODE_4K:
  1094. tmp |= 0x7;
  1095. break;
  1096. default:
  1097. case TRANSMISSION_MODE_8K:
  1098. tmp |= 0x8;
  1099. break;
  1100. }
  1101. dib7000p_write_word(state, 32, tmp);
  1102. /* P_ctrl_sfreq_inh=0, P_ctrl_sfreq_step */
  1103. tmp = (0 << 4);
  1104. switch (ch->transmission_mode) {
  1105. case TRANSMISSION_MODE_2K:
  1106. tmp |= 0x6;
  1107. break;
  1108. case TRANSMISSION_MODE_4K:
  1109. tmp |= 0x7;
  1110. break;
  1111. default:
  1112. case TRANSMISSION_MODE_8K:
  1113. tmp |= 0x8;
  1114. break;
  1115. }
  1116. dib7000p_write_word(state, 33, tmp);
  1117. tmp = dib7000p_read_word(state, 509);
  1118. if (!((tmp >> 6) & 0x1)) {
  1119. /* restart the fec */
  1120. tmp = dib7000p_read_word(state, 771);
  1121. dib7000p_write_word(state, 771, tmp | (1 << 1));
  1122. dib7000p_write_word(state, 771, tmp);
  1123. msleep(40);
  1124. tmp = dib7000p_read_word(state, 509);
  1125. }
  1126. // we achieved a lock - it's time to update the osc freq
  1127. if ((tmp >> 6) & 0x1) {
  1128. dib7000p_update_timf(state);
  1129. /* P_timf_alpha += 2 */
  1130. tmp = dib7000p_read_word(state, 26);
  1131. dib7000p_write_word(state, 26, (tmp & ~(0xf << 12)) | ((((tmp >> 12) & 0xf) + 5) << 12));
  1132. }
  1133. if (state->cfg.spur_protect)
  1134. dib7000p_spur_protect(state, ch->frequency / 1000, BANDWIDTH_TO_KHZ(ch->bandwidth_hz));
  1135. dib7000p_set_bandwidth(state, BANDWIDTH_TO_KHZ(ch->bandwidth_hz));
  1136. dib7000p_reset_stats(demod);
  1137. return 0;
  1138. }
  1139. static int dib7000p_wakeup(struct dvb_frontend *demod)
  1140. {
  1141. struct dib7000p_state *state = demod->demodulator_priv;
  1142. dib7000p_set_power_mode(state, DIB7000P_POWER_ALL);
  1143. dib7000p_set_adc_state(state, DIBX000_SLOW_ADC_ON);
  1144. if (state->version == SOC7090)
  1145. dib7000p_sad_calib(state);
  1146. return 0;
  1147. }
  1148. static int dib7000p_sleep(struct dvb_frontend *demod)
  1149. {
  1150. struct dib7000p_state *state = demod->demodulator_priv;
  1151. if (state->version == SOC7090)
  1152. return dib7000p_set_power_mode(state, DIB7000P_POWER_INTERFACE_ONLY);
  1153. return dib7000p_set_output_mode(state, OUTMODE_HIGH_Z) | dib7000p_set_power_mode(state, DIB7000P_POWER_INTERFACE_ONLY);
  1154. }
  1155. static int dib7000p_identify(struct dib7000p_state *st)
  1156. {
  1157. u16 value;
  1158. dprintk("checking demod on I2C address: %d (%x)", st->i2c_addr, st->i2c_addr);
  1159. if ((value = dib7000p_read_word(st, 768)) != 0x01b3) {
  1160. dprintk("wrong Vendor ID (read=0x%x)", value);
  1161. return -EREMOTEIO;
  1162. }
  1163. if ((value = dib7000p_read_word(st, 769)) != 0x4000) {
  1164. dprintk("wrong Device ID (%x)", value);
  1165. return -EREMOTEIO;
  1166. }
  1167. return 0;
  1168. }
  1169. static int dib7000p_get_frontend(struct dvb_frontend *fe)
  1170. {
  1171. struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
  1172. struct dib7000p_state *state = fe->demodulator_priv;
  1173. u16 tps = dib7000p_read_word(state, 463);
  1174. fep->inversion = INVERSION_AUTO;
  1175. fep->bandwidth_hz = BANDWIDTH_TO_HZ(state->current_bandwidth);
  1176. switch ((tps >> 8) & 0x3) {
  1177. case 0:
  1178. fep->transmission_mode = TRANSMISSION_MODE_2K;
  1179. break;
  1180. case 1:
  1181. fep->transmission_mode = TRANSMISSION_MODE_8K;
  1182. break;
  1183. /* case 2: fep->transmission_mode = TRANSMISSION_MODE_4K; break; */
  1184. }
  1185. switch (tps & 0x3) {
  1186. case 0:
  1187. fep->guard_interval = GUARD_INTERVAL_1_32;
  1188. break;
  1189. case 1:
  1190. fep->guard_interval = GUARD_INTERVAL_1_16;
  1191. break;
  1192. case 2:
  1193. fep->guard_interval = GUARD_INTERVAL_1_8;
  1194. break;
  1195. case 3:
  1196. fep->guard_interval = GUARD_INTERVAL_1_4;
  1197. break;
  1198. }
  1199. switch ((tps >> 14) & 0x3) {
  1200. case 0:
  1201. fep->modulation = QPSK;
  1202. break;
  1203. case 1:
  1204. fep->modulation = QAM_16;
  1205. break;
  1206. case 2:
  1207. default:
  1208. fep->modulation = QAM_64;
  1209. break;
  1210. }
  1211. /* as long as the frontend_param structure is fixed for hierarchical transmission I refuse to use it */
  1212. /* (tps >> 13) & 0x1 == hrch is used, (tps >> 10) & 0x7 == alpha */
  1213. fep->hierarchy = HIERARCHY_NONE;
  1214. switch ((tps >> 5) & 0x7) {
  1215. case 1:
  1216. fep->code_rate_HP = FEC_1_2;
  1217. break;
  1218. case 2:
  1219. fep->code_rate_HP = FEC_2_3;
  1220. break;
  1221. case 3:
  1222. fep->code_rate_HP = FEC_3_4;
  1223. break;
  1224. case 5:
  1225. fep->code_rate_HP = FEC_5_6;
  1226. break;
  1227. case 7:
  1228. default:
  1229. fep->code_rate_HP = FEC_7_8;
  1230. break;
  1231. }
  1232. switch ((tps >> 2) & 0x7) {
  1233. case 1:
  1234. fep->code_rate_LP = FEC_1_2;
  1235. break;
  1236. case 2:
  1237. fep->code_rate_LP = FEC_2_3;
  1238. break;
  1239. case 3:
  1240. fep->code_rate_LP = FEC_3_4;
  1241. break;
  1242. case 5:
  1243. fep->code_rate_LP = FEC_5_6;
  1244. break;
  1245. case 7:
  1246. default:
  1247. fep->code_rate_LP = FEC_7_8;
  1248. break;
  1249. }
  1250. /* native interleaver: (dib7000p_read_word(state, 464) >> 5) & 0x1 */
  1251. return 0;
  1252. }
  1253. static int dib7000p_set_frontend(struct dvb_frontend *fe)
  1254. {
  1255. struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
  1256. struct dib7000p_state *state = fe->demodulator_priv;
  1257. int time, ret;
  1258. if (state->version == SOC7090)
  1259. dib7090_set_diversity_in(fe, 0);
  1260. else
  1261. dib7000p_set_output_mode(state, OUTMODE_HIGH_Z);
  1262. /* maybe the parameter has been changed */
  1263. state->sfn_workaround_active = buggy_sfn_workaround;
  1264. if (fe->ops.tuner_ops.set_params)
  1265. fe->ops.tuner_ops.set_params(fe);
  1266. /* start up the AGC */
  1267. state->agc_state = 0;
  1268. do {
  1269. time = dib7000p_agc_startup(fe);
  1270. if (time != -1)
  1271. msleep(time);
  1272. } while (time != -1);
  1273. if (fep->transmission_mode == TRANSMISSION_MODE_AUTO ||
  1274. fep->guard_interval == GUARD_INTERVAL_AUTO || fep->modulation == QAM_AUTO || fep->code_rate_HP == FEC_AUTO) {
  1275. int i = 800, found;
  1276. dib7000p_autosearch_start(fe);
  1277. do {
  1278. msleep(1);
  1279. found = dib7000p_autosearch_is_irq(fe);
  1280. } while (found == 0 && i--);
  1281. dprintk("autosearch returns: %d", found);
  1282. if (found == 0 || found == 1)
  1283. return 0;
  1284. dib7000p_get_frontend(fe);
  1285. }
  1286. ret = dib7000p_tune(fe);
  1287. /* make this a config parameter */
  1288. if (state->version == SOC7090) {
  1289. dib7090_set_output_mode(fe, state->cfg.output_mode);
  1290. if (state->cfg.enMpegOutput == 0) {
  1291. dib7090_setDibTxMux(state, MPEG_ON_DIBTX);
  1292. dib7090_setHostBusMux(state, DIBTX_ON_HOSTBUS);
  1293. }
  1294. } else
  1295. dib7000p_set_output_mode(state, state->cfg.output_mode);
  1296. return ret;
  1297. }
  1298. static int dib7000p_get_stats(struct dvb_frontend *fe, fe_status_t stat);
  1299. static int dib7000p_read_status(struct dvb_frontend *fe, fe_status_t * stat)
  1300. {
  1301. struct dib7000p_state *state = fe->demodulator_priv;
  1302. u16 lock = dib7000p_read_word(state, 509);
  1303. *stat = 0;
  1304. if (lock & 0x8000)
  1305. *stat |= FE_HAS_SIGNAL;
  1306. if (lock & 0x3000)
  1307. *stat |= FE_HAS_CARRIER;
  1308. if (lock & 0x0100)
  1309. *stat |= FE_HAS_VITERBI;
  1310. if (lock & 0x0010)
  1311. *stat |= FE_HAS_SYNC;
  1312. if ((lock & 0x0038) == 0x38)
  1313. *stat |= FE_HAS_LOCK;
  1314. dib7000p_get_stats(fe, *stat);
  1315. return 0;
  1316. }
  1317. static int dib7000p_read_ber(struct dvb_frontend *fe, u32 * ber)
  1318. {
  1319. struct dib7000p_state *state = fe->demodulator_priv;
  1320. *ber = (dib7000p_read_word(state, 500) << 16) | dib7000p_read_word(state, 501);
  1321. return 0;
  1322. }
  1323. static int dib7000p_read_unc_blocks(struct dvb_frontend *fe, u32 * unc)
  1324. {
  1325. struct dib7000p_state *state = fe->demodulator_priv;
  1326. *unc = dib7000p_read_word(state, 506);
  1327. return 0;
  1328. }
  1329. static int dib7000p_read_signal_strength(struct dvb_frontend *fe, u16 * strength)
  1330. {
  1331. struct dib7000p_state *state = fe->demodulator_priv;
  1332. u16 val = dib7000p_read_word(state, 394);
  1333. *strength = 65535 - val;
  1334. return 0;
  1335. }
  1336. static u32 dib7000p_get_snr(struct dvb_frontend *fe)
  1337. {
  1338. struct dib7000p_state *state = fe->demodulator_priv;
  1339. u16 val;
  1340. s32 signal_mant, signal_exp, noise_mant, noise_exp;
  1341. u32 result = 0;
  1342. val = dib7000p_read_word(state, 479);
  1343. noise_mant = (val >> 4) & 0xff;
  1344. noise_exp = ((val & 0xf) << 2);
  1345. val = dib7000p_read_word(state, 480);
  1346. noise_exp += ((val >> 14) & 0x3);
  1347. if ((noise_exp & 0x20) != 0)
  1348. noise_exp -= 0x40;
  1349. signal_mant = (val >> 6) & 0xFF;
  1350. signal_exp = (val & 0x3F);
  1351. if ((signal_exp & 0x20) != 0)
  1352. signal_exp -= 0x40;
  1353. if (signal_mant != 0)
  1354. result = intlog10(2) * 10 * signal_exp + 10 * intlog10(signal_mant);
  1355. else
  1356. result = intlog10(2) * 10 * signal_exp - 100;
  1357. if (noise_mant != 0)
  1358. result -= intlog10(2) * 10 * noise_exp + 10 * intlog10(noise_mant);
  1359. else
  1360. result -= intlog10(2) * 10 * noise_exp - 100;
  1361. return result;
  1362. }
  1363. static int dib7000p_read_snr(struct dvb_frontend *fe, u16 *snr)
  1364. {
  1365. u32 result;
  1366. result = dib7000p_get_snr(fe);
  1367. *snr = result / ((1 << 24) / 10);
  1368. return 0;
  1369. }
  1370. static void dib7000p_reset_stats(struct dvb_frontend *demod)
  1371. {
  1372. struct dib7000p_state *state = demod->demodulator_priv;
  1373. struct dtv_frontend_properties *c = &demod->dtv_property_cache;
  1374. u32 ucb;
  1375. memset(&c->strength, 0, sizeof(c->strength));
  1376. memset(&c->cnr, 0, sizeof(c->cnr));
  1377. memset(&c->post_bit_error, 0, sizeof(c->post_bit_error));
  1378. memset(&c->post_bit_count, 0, sizeof(c->post_bit_count));
  1379. memset(&c->block_error, 0, sizeof(c->block_error));
  1380. c->strength.len = 1;
  1381. c->cnr.len = 1;
  1382. c->block_error.len = 1;
  1383. c->block_count.len = 1;
  1384. c->post_bit_error.len = 1;
  1385. c->post_bit_count.len = 1;
  1386. c->strength.stat[0].scale = FE_SCALE_DECIBEL;
  1387. c->strength.stat[0].uvalue = 0;
  1388. c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1389. c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1390. c->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1391. c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1392. c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1393. dib7000p_read_unc_blocks(demod, &ucb);
  1394. state->old_ucb = ucb;
  1395. state->ber_jiffies_stats = 0;
  1396. state->per_jiffies_stats = 0;
  1397. }
  1398. struct linear_segments {
  1399. unsigned x;
  1400. signed y;
  1401. };
  1402. /*
  1403. * Table to estimate signal strength in dBm.
  1404. * This table should be empirically determinated by measuring the signal
  1405. * strength generated by a RF generator directly connected into
  1406. * a device.
  1407. * This table was determinated by measuring the signal strength generated
  1408. * by a DTA-2111 RF generator directly connected into a dib7000p device
  1409. * (a Hauppauge Nova-TD stick), using a good quality 3 meters length
  1410. * RC6 cable and good RC6 connectors, connected directly to antenna 1.
  1411. * As the minimum output power of DTA-2111 is -31dBm, a 16 dBm attenuator
  1412. * were used, for the lower power values.
  1413. * The real value can actually be on other devices, or even at the
  1414. * second antena input, depending on several factors, like if LNA
  1415. * is enabled or not, if diversity is enabled, type of connectors, etc.
  1416. * Yet, it is better to use this measure in dB than a random non-linear
  1417. * percentage value, especially for antenna adjustments.
  1418. * On my tests, the precision of the measure using this table is about
  1419. * 0.5 dB, with sounds reasonable enough to adjust antennas.
  1420. */
  1421. #define DB_OFFSET 131000
  1422. static struct linear_segments strength_to_db_table[] = {
  1423. { 63630, DB_OFFSET - 20500},
  1424. { 62273, DB_OFFSET - 21000},
  1425. { 60162, DB_OFFSET - 22000},
  1426. { 58730, DB_OFFSET - 23000},
  1427. { 58294, DB_OFFSET - 24000},
  1428. { 57778, DB_OFFSET - 25000},
  1429. { 57320, DB_OFFSET - 26000},
  1430. { 56779, DB_OFFSET - 27000},
  1431. { 56293, DB_OFFSET - 28000},
  1432. { 55724, DB_OFFSET - 29000},
  1433. { 55145, DB_OFFSET - 30000},
  1434. { 54680, DB_OFFSET - 31000},
  1435. { 54293, DB_OFFSET - 32000},
  1436. { 53813, DB_OFFSET - 33000},
  1437. { 53427, DB_OFFSET - 34000},
  1438. { 52981, DB_OFFSET - 35000},
  1439. { 52636, DB_OFFSET - 36000},
  1440. { 52014, DB_OFFSET - 37000},
  1441. { 51674, DB_OFFSET - 38000},
  1442. { 50692, DB_OFFSET - 39000},
  1443. { 49824, DB_OFFSET - 40000},
  1444. { 49052, DB_OFFSET - 41000},
  1445. { 48436, DB_OFFSET - 42000},
  1446. { 47836, DB_OFFSET - 43000},
  1447. { 47368, DB_OFFSET - 44000},
  1448. { 46468, DB_OFFSET - 45000},
  1449. { 45597, DB_OFFSET - 46000},
  1450. { 44586, DB_OFFSET - 47000},
  1451. { 43667, DB_OFFSET - 48000},
  1452. { 42673, DB_OFFSET - 49000},
  1453. { 41816, DB_OFFSET - 50000},
  1454. { 40876, DB_OFFSET - 51000},
  1455. { 0, 0},
  1456. };
  1457. static u32 interpolate_value(u32 value, struct linear_segments *segments,
  1458. unsigned len)
  1459. {
  1460. u64 tmp64;
  1461. u32 dx;
  1462. s32 dy;
  1463. int i, ret;
  1464. if (value >= segments[0].x)
  1465. return segments[0].y;
  1466. if (value < segments[len-1].x)
  1467. return segments[len-1].y;
  1468. for (i = 1; i < len - 1; i++) {
  1469. /* If value is identical, no need to interpolate */
  1470. if (value == segments[i].x)
  1471. return segments[i].y;
  1472. if (value > segments[i].x)
  1473. break;
  1474. }
  1475. /* Linear interpolation between the two (x,y) points */
  1476. dy = segments[i - 1].y - segments[i].y;
  1477. dx = segments[i - 1].x - segments[i].x;
  1478. tmp64 = value - segments[i].x;
  1479. tmp64 *= dy;
  1480. do_div(tmp64, dx);
  1481. ret = segments[i].y + tmp64;
  1482. return ret;
  1483. }
  1484. /* FIXME: may require changes - this one was borrowed from dib8000 */
  1485. static u32 dib7000p_get_time_us(struct dvb_frontend *demod, int layer)
  1486. {
  1487. struct dtv_frontend_properties *c = &demod->dtv_property_cache;
  1488. u64 time_us, tmp64;
  1489. u32 tmp, denom;
  1490. int guard, rate_num, rate_denum = 1, bits_per_symbol;
  1491. int interleaving = 0, fft_div;
  1492. switch (c->guard_interval) {
  1493. case GUARD_INTERVAL_1_4:
  1494. guard = 4;
  1495. break;
  1496. case GUARD_INTERVAL_1_8:
  1497. guard = 8;
  1498. break;
  1499. case GUARD_INTERVAL_1_16:
  1500. guard = 16;
  1501. break;
  1502. default:
  1503. case GUARD_INTERVAL_1_32:
  1504. guard = 32;
  1505. break;
  1506. }
  1507. switch (c->transmission_mode) {
  1508. case TRANSMISSION_MODE_2K:
  1509. fft_div = 4;
  1510. break;
  1511. case TRANSMISSION_MODE_4K:
  1512. fft_div = 2;
  1513. break;
  1514. default:
  1515. case TRANSMISSION_MODE_8K:
  1516. fft_div = 1;
  1517. break;
  1518. }
  1519. switch (c->modulation) {
  1520. case DQPSK:
  1521. case QPSK:
  1522. bits_per_symbol = 2;
  1523. break;
  1524. case QAM_16:
  1525. bits_per_symbol = 4;
  1526. break;
  1527. default:
  1528. case QAM_64:
  1529. bits_per_symbol = 6;
  1530. break;
  1531. }
  1532. switch ((c->hierarchy == 0 || 1 == 1) ? c->code_rate_HP : c->code_rate_LP) {
  1533. case FEC_1_2:
  1534. rate_num = 1;
  1535. rate_denum = 2;
  1536. break;
  1537. case FEC_2_3:
  1538. rate_num = 2;
  1539. rate_denum = 3;
  1540. break;
  1541. case FEC_3_4:
  1542. rate_num = 3;
  1543. rate_denum = 4;
  1544. break;
  1545. case FEC_5_6:
  1546. rate_num = 5;
  1547. rate_denum = 6;
  1548. break;
  1549. default:
  1550. case FEC_7_8:
  1551. rate_num = 7;
  1552. rate_denum = 8;
  1553. break;
  1554. }
  1555. interleaving = interleaving;
  1556. denom = bits_per_symbol * rate_num * fft_div * 384;
  1557. /* If calculus gets wrong, wait for 1s for the next stats */
  1558. if (!denom)
  1559. return 0;
  1560. /* Estimate the period for the total bit rate */
  1561. time_us = rate_denum * (1008 * 1562500L);
  1562. tmp64 = time_us;
  1563. do_div(tmp64, guard);
  1564. time_us = time_us + tmp64;
  1565. time_us += denom / 2;
  1566. do_div(time_us, denom);
  1567. tmp = 1008 * 96 * interleaving;
  1568. time_us += tmp + tmp / guard;
  1569. return time_us;
  1570. }
  1571. static int dib7000p_get_stats(struct dvb_frontend *demod, fe_status_t stat)
  1572. {
  1573. struct dib7000p_state *state = demod->demodulator_priv;
  1574. struct dtv_frontend_properties *c = &demod->dtv_property_cache;
  1575. int i;
  1576. int show_per_stats = 0;
  1577. u32 time_us = 0, val, snr;
  1578. u64 blocks, ucb;
  1579. s32 db;
  1580. u16 strength;
  1581. /* Get Signal strength */
  1582. dib7000p_read_signal_strength(demod, &strength);
  1583. val = strength;
  1584. db = interpolate_value(val,
  1585. strength_to_db_table,
  1586. ARRAY_SIZE(strength_to_db_table)) - DB_OFFSET;
  1587. c->strength.stat[0].svalue = db;
  1588. /* UCB/BER/CNR measures require lock */
  1589. if (!(stat & FE_HAS_LOCK)) {
  1590. c->cnr.len = 1;
  1591. c->block_count.len = 1;
  1592. c->block_error.len = 1;
  1593. c->post_bit_error.len = 1;
  1594. c->post_bit_count.len = 1;
  1595. c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1596. c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1597. c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1598. c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1599. c->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1600. return 0;
  1601. }
  1602. /* Check if time for stats was elapsed */
  1603. if (time_after(jiffies, state->per_jiffies_stats)) {
  1604. state->per_jiffies_stats = jiffies + msecs_to_jiffies(1000);
  1605. /* Get SNR */
  1606. snr = dib7000p_get_snr(demod);
  1607. if (snr)
  1608. snr = (1000L * snr) >> 24;
  1609. else
  1610. snr = 0;
  1611. c->cnr.stat[0].svalue = snr;
  1612. c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
  1613. /* Get UCB measures */
  1614. dib7000p_read_unc_blocks(demod, &val);
  1615. ucb = val - state->old_ucb;
  1616. if (val < state->old_ucb)
  1617. ucb += 0x100000000LL;
  1618. c->block_error.stat[0].scale = FE_SCALE_COUNTER;
  1619. c->block_error.stat[0].uvalue = ucb;
  1620. /* Estimate the number of packets based on bitrate */
  1621. if (!time_us)
  1622. time_us = dib7000p_get_time_us(demod, -1);
  1623. if (time_us) {
  1624. blocks = 1250000ULL * 1000000ULL;
  1625. do_div(blocks, time_us * 8 * 204);
  1626. c->block_count.stat[0].scale = FE_SCALE_COUNTER;
  1627. c->block_count.stat[0].uvalue += blocks;
  1628. }
  1629. show_per_stats = 1;
  1630. }
  1631. /* Get post-BER measures */
  1632. if (time_after(jiffies, state->ber_jiffies_stats)) {
  1633. time_us = dib7000p_get_time_us(demod, -1);
  1634. state->ber_jiffies_stats = jiffies + msecs_to_jiffies((time_us + 500) / 1000);
  1635. dprintk("Next all layers stats available in %u us.", time_us);
  1636. dib7000p_read_ber(demod, &val);
  1637. c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
  1638. c->post_bit_error.stat[0].uvalue += val;
  1639. c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
  1640. c->post_bit_count.stat[0].uvalue += 100000000;
  1641. }
  1642. /* Get PER measures */
  1643. if (show_per_stats) {
  1644. dib7000p_read_unc_blocks(demod, &val);
  1645. c->block_error.stat[0].scale = FE_SCALE_COUNTER;
  1646. c->block_error.stat[0].uvalue += val;
  1647. time_us = dib7000p_get_time_us(demod, i);
  1648. if (time_us) {
  1649. blocks = 1250000ULL * 1000000ULL;
  1650. do_div(blocks, time_us * 8 * 204);
  1651. c->block_count.stat[0].scale = FE_SCALE_COUNTER;
  1652. c->block_count.stat[0].uvalue += blocks;
  1653. }
  1654. }
  1655. return 0;
  1656. }
  1657. static int dib7000p_fe_get_tune_settings(struct dvb_frontend *fe, struct dvb_frontend_tune_settings *tune)
  1658. {
  1659. tune->min_delay_ms = 1000;
  1660. return 0;
  1661. }
  1662. static void dib7000p_release(struct dvb_frontend *demod)
  1663. {
  1664. struct dib7000p_state *st = demod->demodulator_priv;
  1665. dibx000_exit_i2c_master(&st->i2c_master);
  1666. i2c_del_adapter(&st->dib7090_tuner_adap);
  1667. kfree(st);
  1668. }
  1669. static int dib7000pc_detection(struct i2c_adapter *i2c_adap)
  1670. {
  1671. u8 *tx, *rx;
  1672. struct i2c_msg msg[2] = {
  1673. {.addr = 18 >> 1, .flags = 0, .len = 2},
  1674. {.addr = 18 >> 1, .flags = I2C_M_RD, .len = 2},
  1675. };
  1676. int ret = 0;
  1677. tx = kzalloc(2*sizeof(u8), GFP_KERNEL);
  1678. if (!tx)
  1679. return -ENOMEM;
  1680. rx = kzalloc(2*sizeof(u8), GFP_KERNEL);
  1681. if (!rx) {
  1682. ret = -ENOMEM;
  1683. goto rx_memory_error;
  1684. }
  1685. msg[0].buf = tx;
  1686. msg[1].buf = rx;
  1687. tx[0] = 0x03;
  1688. tx[1] = 0x00;
  1689. if (i2c_transfer(i2c_adap, msg, 2) == 2)
  1690. if (rx[0] == 0x01 && rx[1] == 0xb3) {
  1691. dprintk("-D- DiB7000PC detected");
  1692. return 1;
  1693. }
  1694. msg[0].addr = msg[1].addr = 0x40;
  1695. if (i2c_transfer(i2c_adap, msg, 2) == 2)
  1696. if (rx[0] == 0x01 && rx[1] == 0xb3) {
  1697. dprintk("-D- DiB7000PC detected");
  1698. return 1;
  1699. }
  1700. dprintk("-D- DiB7000PC not detected");
  1701. kfree(rx);
  1702. rx_memory_error:
  1703. kfree(tx);
  1704. return ret;
  1705. }
  1706. static struct i2c_adapter *dib7000p_get_i2c_master(struct dvb_frontend *demod, enum dibx000_i2c_interface intf, int gating)
  1707. {
  1708. struct dib7000p_state *st = demod->demodulator_priv;
  1709. return dibx000_get_i2c_adapter(&st->i2c_master, intf, gating);
  1710. }
  1711. static int dib7000p_pid_filter_ctrl(struct dvb_frontend *fe, u8 onoff)
  1712. {
  1713. struct dib7000p_state *state = fe->demodulator_priv;
  1714. u16 val = dib7000p_read_word(state, 235) & 0xffef;
  1715. val |= (onoff & 0x1) << 4;
  1716. dprintk("PID filter enabled %d", onoff);
  1717. return dib7000p_write_word(state, 235, val);
  1718. }
  1719. static int dib7000p_pid_filter(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff)
  1720. {
  1721. struct dib7000p_state *state = fe->demodulator_priv;
  1722. dprintk("PID filter: index %x, PID %d, OnOff %d", id, pid, onoff);
  1723. return dib7000p_write_word(state, 241 + id, onoff ? (1 << 13) | pid : 0);
  1724. }
  1725. static int dib7000p_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, struct dib7000p_config cfg[])
  1726. {
  1727. struct dib7000p_state *dpst;
  1728. int k = 0;
  1729. u8 new_addr = 0;
  1730. dpst = kzalloc(sizeof(struct dib7000p_state), GFP_KERNEL);
  1731. if (!dpst)
  1732. return -ENOMEM;
  1733. dpst->i2c_adap = i2c;
  1734. mutex_init(&dpst->i2c_buffer_lock);
  1735. for (k = no_of_demods - 1; k >= 0; k--) {
  1736. dpst->cfg = cfg[k];
  1737. /* designated i2c address */
  1738. if (cfg[k].default_i2c_addr != 0)
  1739. new_addr = cfg[k].default_i2c_addr + (k << 1);
  1740. else
  1741. new_addr = (0x40 + k) << 1;
  1742. dpst->i2c_addr = new_addr;
  1743. dib7000p_write_word(dpst, 1287, 0x0003); /* sram lead in, rdy */
  1744. if (dib7000p_identify(dpst) != 0) {
  1745. dpst->i2c_addr = default_addr;
  1746. dib7000p_write_word(dpst, 1287, 0x0003); /* sram lead in, rdy */
  1747. if (dib7000p_identify(dpst) != 0) {
  1748. dprintk("DiB7000P #%d: not identified\n", k);
  1749. kfree(dpst);
  1750. return -EIO;
  1751. }
  1752. }
  1753. /* start diversity to pull_down div_str - just for i2c-enumeration */
  1754. dib7000p_set_output_mode(dpst, OUTMODE_DIVERSITY);
  1755. /* set new i2c address and force divstart */
  1756. dib7000p_write_word(dpst, 1285, (new_addr << 2) | 0x2);
  1757. dprintk("IC %d initialized (to i2c_address 0x%x)", k, new_addr);
  1758. }
  1759. for (k = 0; k < no_of_demods; k++) {
  1760. dpst->cfg = cfg[k];
  1761. if (cfg[k].default_i2c_addr != 0)
  1762. dpst->i2c_addr = (cfg[k].default_i2c_addr + k) << 1;
  1763. else
  1764. dpst->i2c_addr = (0x40 + k) << 1;
  1765. // unforce divstr
  1766. dib7000p_write_word(dpst, 1285, dpst->i2c_addr << 2);
  1767. /* deactivate div - it was just for i2c-enumeration */
  1768. dib7000p_set_output_mode(dpst, OUTMODE_HIGH_Z);
  1769. }
  1770. kfree(dpst);
  1771. return 0;
  1772. }
  1773. static const s32 lut_1000ln_mant[] = {
  1774. 6908, 6956, 7003, 7047, 7090, 7131, 7170, 7208, 7244, 7279, 7313, 7346, 7377, 7408, 7438, 7467, 7495, 7523, 7549, 7575, 7600
  1775. };
  1776. static s32 dib7000p_get_adc_power(struct dvb_frontend *fe)
  1777. {
  1778. struct dib7000p_state *state = fe->demodulator_priv;
  1779. u32 tmp_val = 0, exp = 0, mant = 0;
  1780. s32 pow_i;
  1781. u16 buf[2];
  1782. u8 ix = 0;
  1783. buf[0] = dib7000p_read_word(state, 0x184);
  1784. buf[1] = dib7000p_read_word(state, 0x185);
  1785. pow_i = (buf[0] << 16) | buf[1];
  1786. dprintk("raw pow_i = %d", pow_i);
  1787. tmp_val = pow_i;
  1788. while (tmp_val >>= 1)
  1789. exp++;
  1790. mant = (pow_i * 1000 / (1 << exp));
  1791. dprintk(" mant = %d exp = %d", mant / 1000, exp);
  1792. ix = (u8) ((mant - 1000) / 100); /* index of the LUT */
  1793. dprintk(" ix = %d", ix);
  1794. pow_i = (lut_1000ln_mant[ix] + 693 * (exp - 20) - 6908);
  1795. pow_i = (pow_i << 8) / 1000;
  1796. dprintk(" pow_i = %d", pow_i);
  1797. return pow_i;
  1798. }
  1799. static int map_addr_to_serpar_number(struct i2c_msg *msg)
  1800. {
  1801. if ((msg->buf[0] <= 15))
  1802. msg->buf[0] -= 1;
  1803. else if (msg->buf[0] == 17)
  1804. msg->buf[0] = 15;
  1805. else if (msg->buf[0] == 16)
  1806. msg->buf[0] = 17;
  1807. else if (msg->buf[0] == 19)
  1808. msg->buf[0] = 16;
  1809. else if (msg->buf[0] >= 21 && msg->buf[0] <= 25)
  1810. msg->buf[0] -= 3;
  1811. else if (msg->buf[0] == 28)
  1812. msg->buf[0] = 23;
  1813. else
  1814. return -EINVAL;
  1815. return 0;
  1816. }
  1817. static int w7090p_tuner_write_serpar(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num)
  1818. {
  1819. struct dib7000p_state *state = i2c_get_adapdata(i2c_adap);
  1820. u8 n_overflow = 1;
  1821. u16 i = 1000;
  1822. u16 serpar_num = msg[0].buf[0];
  1823. while (n_overflow == 1 && i) {
  1824. n_overflow = (dib7000p_read_word(state, 1984) >> 1) & 0x1;
  1825. i--;
  1826. if (i == 0)
  1827. dprintk("Tuner ITF: write busy (overflow)");
  1828. }
  1829. dib7000p_write_word(state, 1985, (1 << 6) | (serpar_num & 0x3f));
  1830. dib7000p_write_word(state, 1986, (msg[0].buf[1] << 8) | msg[0].buf[2]);
  1831. return num;
  1832. }
  1833. static int w7090p_tuner_read_serpar(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num)
  1834. {
  1835. struct dib7000p_state *state = i2c_get_adapdata(i2c_adap);
  1836. u8 n_overflow = 1, n_empty = 1;
  1837. u16 i = 1000;
  1838. u16 serpar_num = msg[0].buf[0];
  1839. u16 read_word;
  1840. while (n_overflow == 1 && i) {
  1841. n_overflow = (dib7000p_read_word(state, 1984) >> 1) & 0x1;
  1842. i--;
  1843. if (i == 0)
  1844. dprintk("TunerITF: read busy (overflow)");
  1845. }
  1846. dib7000p_write_word(state, 1985, (0 << 6) | (serpar_num & 0x3f));
  1847. i = 1000;
  1848. while (n_empty == 1 && i) {
  1849. n_empty = dib7000p_read_word(state, 1984) & 0x1;
  1850. i--;
  1851. if (i == 0)
  1852. dprintk("TunerITF: read busy (empty)");
  1853. }
  1854. read_word = dib7000p_read_word(state, 1987);
  1855. msg[1].buf[0] = (read_word >> 8) & 0xff;
  1856. msg[1].buf[1] = (read_word) & 0xff;
  1857. return num;
  1858. }
  1859. static int w7090p_tuner_rw_serpar(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num)
  1860. {
  1861. if (map_addr_to_serpar_number(&msg[0]) == 0) { /* else = Tuner regs to ignore : DIG_CFG, CTRL_RF_LT, PLL_CFG, PWM1_REG, ADCCLK, DIG_CFG_3; SLEEP_EN... */
  1862. if (num == 1) { /* write */
  1863. return w7090p_tuner_write_serpar(i2c_adap, msg, 1);
  1864. } else { /* read */
  1865. return w7090p_tuner_read_serpar(i2c_adap, msg, 2);
  1866. }
  1867. }
  1868. return num;
  1869. }
  1870. static int dib7090p_rw_on_apb(struct i2c_adapter *i2c_adap,
  1871. struct i2c_msg msg[], int num, u16 apb_address)
  1872. {
  1873. struct dib7000p_state *state = i2c_get_adapdata(i2c_adap);
  1874. u16 word;
  1875. if (num == 1) { /* write */
  1876. dib7000p_write_word(state, apb_address, ((msg[0].buf[1] << 8) | (msg[0].buf[2])));
  1877. } else {
  1878. word = dib7000p_read_word(state, apb_address);
  1879. msg[1].buf[0] = (word >> 8) & 0xff;
  1880. msg[1].buf[1] = (word) & 0xff;
  1881. }
  1882. return num;
  1883. }
  1884. static int dib7090_tuner_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num)
  1885. {
  1886. struct dib7000p_state *state = i2c_get_adapdata(i2c_adap);
  1887. u16 apb_address = 0, word;
  1888. int i = 0;
  1889. switch (msg[0].buf[0]) {
  1890. case 0x12:
  1891. apb_address = 1920;
  1892. break;
  1893. case 0x14:
  1894. apb_address = 1921;
  1895. break;
  1896. case 0x24:
  1897. apb_address = 1922;
  1898. break;
  1899. case 0x1a:
  1900. apb_address = 1923;
  1901. break;
  1902. case 0x22:
  1903. apb_address = 1924;
  1904. break;
  1905. case 0x33:
  1906. apb_address = 1926;
  1907. break;
  1908. case 0x34:
  1909. apb_address = 1927;
  1910. break;
  1911. case 0x35:
  1912. apb_address = 1928;
  1913. break;
  1914. case 0x36:
  1915. apb_address = 1929;
  1916. break;
  1917. case 0x37:
  1918. apb_address = 1930;
  1919. break;
  1920. case 0x38:
  1921. apb_address = 1931;
  1922. break;
  1923. case 0x39:
  1924. apb_address = 1932;
  1925. break;
  1926. case 0x2a:
  1927. apb_address = 1935;
  1928. break;
  1929. case 0x2b:
  1930. apb_address = 1936;
  1931. break;
  1932. case 0x2c:
  1933. apb_address = 1937;
  1934. break;
  1935. case 0x2d:
  1936. apb_address = 1938;
  1937. break;
  1938. case 0x2e:
  1939. apb_address = 1939;
  1940. break;
  1941. case 0x2f:
  1942. apb_address = 1940;
  1943. break;
  1944. case 0x30:
  1945. apb_address = 1941;
  1946. break;
  1947. case 0x31:
  1948. apb_address = 1942;
  1949. break;
  1950. case 0x32:
  1951. apb_address = 1943;
  1952. break;
  1953. case 0x3e:
  1954. apb_address = 1944;
  1955. break;
  1956. case 0x3f:
  1957. apb_address = 1945;
  1958. break;
  1959. case 0x40:
  1960. apb_address = 1948;
  1961. break;
  1962. case 0x25:
  1963. apb_address = 914;
  1964. break;
  1965. case 0x26:
  1966. apb_address = 915;
  1967. break;
  1968. case 0x27:
  1969. apb_address = 917;
  1970. break;
  1971. case 0x28:
  1972. apb_address = 916;
  1973. break;
  1974. case 0x1d:
  1975. i = ((dib7000p_read_word(state, 72) >> 12) & 0x3);
  1976. word = dib7000p_read_word(state, 384 + i);
  1977. msg[1].buf[0] = (word >> 8) & 0xff;
  1978. msg[1].buf[1] = (word) & 0xff;
  1979. return num;
  1980. case 0x1f:
  1981. if (num == 1) { /* write */
  1982. word = (u16) ((msg[0].buf[1] << 8) | msg[0].buf[2]);
  1983. word &= 0x3;
  1984. word = (dib7000p_read_word(state, 72) & ~(3 << 12)) | (word << 12);
  1985. dib7000p_write_word(state, 72, word); /* Set the proper input */
  1986. return num;
  1987. }
  1988. }
  1989. if (apb_address != 0) /* R/W acces via APB */
  1990. return dib7090p_rw_on_apb(i2c_adap, msg, num, apb_address);
  1991. else /* R/W access via SERPAR */
  1992. return w7090p_tuner_rw_serpar(i2c_adap, msg, num);
  1993. return 0;
  1994. }
  1995. static u32 dib7000p_i2c_func(struct i2c_adapter *adapter)
  1996. {
  1997. return I2C_FUNC_I2C;
  1998. }
  1999. static struct i2c_algorithm dib7090_tuner_xfer_algo = {
  2000. .master_xfer = dib7090_tuner_xfer,
  2001. .functionality = dib7000p_i2c_func,
  2002. };
  2003. static struct i2c_adapter *dib7090_get_i2c_tuner(struct dvb_frontend *fe)
  2004. {
  2005. struct dib7000p_state *st = fe->demodulator_priv;
  2006. return &st->dib7090_tuner_adap;
  2007. }
  2008. static int dib7090_host_bus_drive(struct dib7000p_state *state, u8 drive)
  2009. {
  2010. u16 reg;
  2011. /* drive host bus 2, 3, 4 */
  2012. reg = dib7000p_read_word(state, 1798) & ~((0x7) | (0x7 << 6) | (0x7 << 12));
  2013. reg |= (drive << 12) | (drive << 6) | drive;
  2014. dib7000p_write_word(state, 1798, reg);
  2015. /* drive host bus 5,6 */
  2016. reg = dib7000p_read_word(state, 1799) & ~((0x7 << 2) | (0x7 << 8));
  2017. reg |= (drive << 8) | (drive << 2);
  2018. dib7000p_write_word(state, 1799, reg);
  2019. /* drive host bus 7, 8, 9 */
  2020. reg = dib7000p_read_word(state, 1800) & ~((0x7) | (0x7 << 6) | (0x7 << 12));
  2021. reg |= (drive << 12) | (drive << 6) | drive;
  2022. dib7000p_write_word(state, 1800, reg);
  2023. /* drive host bus 10, 11 */
  2024. reg = dib7000p_read_word(state, 1801) & ~((0x7 << 2) | (0x7 << 8));
  2025. reg |= (drive << 8) | (drive << 2);
  2026. dib7000p_write_word(state, 1801, reg);
  2027. /* drive host bus 12, 13, 14 */
  2028. reg = dib7000p_read_word(state, 1802) & ~((0x7) | (0x7 << 6) | (0x7 << 12));
  2029. reg |= (drive << 12) | (drive << 6) | drive;
  2030. dib7000p_write_word(state, 1802, reg);
  2031. return 0;
  2032. }
  2033. static u32 dib7090_calcSyncFreq(u32 P_Kin, u32 P_Kout, u32 insertExtSynchro, u32 syncSize)
  2034. {
  2035. u32 quantif = 3;
  2036. u32 nom = (insertExtSynchro * P_Kin + syncSize);
  2037. u32 denom = P_Kout;
  2038. u32 syncFreq = ((nom << quantif) / denom);
  2039. if ((syncFreq & ((1 << quantif) - 1)) != 0)
  2040. syncFreq = (syncFreq >> quantif) + 1;
  2041. else
  2042. syncFreq = (syncFreq >> quantif);
  2043. if (syncFreq != 0)
  2044. syncFreq = syncFreq - 1;
  2045. return syncFreq;
  2046. }
  2047. static int dib7090_cfg_DibTx(struct dib7000p_state *state, u32 P_Kin, u32 P_Kout, u32 insertExtSynchro, u32 synchroMode, u32 syncWord, u32 syncSize)
  2048. {
  2049. dprintk("Configure DibStream Tx");
  2050. dib7000p_write_word(state, 1615, 1);
  2051. dib7000p_write_word(state, 1603, P_Kin);
  2052. dib7000p_write_word(state, 1605, P_Kout);
  2053. dib7000p_write_word(state, 1606, insertExtSynchro);
  2054. dib7000p_write_word(state, 1608, synchroMode);
  2055. dib7000p_write_word(state, 1609, (syncWord >> 16) & 0xffff);
  2056. dib7000p_write_word(state, 1610, syncWord & 0xffff);
  2057. dib7000p_write_word(state, 1612, syncSize);
  2058. dib7000p_write_word(state, 1615, 0);
  2059. return 0;
  2060. }
  2061. static int dib7090_cfg_DibRx(struct dib7000p_state *state, u32 P_Kin, u32 P_Kout, u32 synchroMode, u32 insertExtSynchro, u32 syncWord, u32 syncSize,
  2062. u32 dataOutRate)
  2063. {
  2064. u32 syncFreq;
  2065. dprintk("Configure DibStream Rx");
  2066. if ((P_Kin != 0) && (P_Kout != 0)) {
  2067. syncFreq = dib7090_calcSyncFreq(P_Kin, P_Kout, insertExtSynchro, syncSize);
  2068. dib7000p_write_word(state, 1542, syncFreq);
  2069. }
  2070. dib7000p_write_word(state, 1554, 1);
  2071. dib7000p_write_word(state, 1536, P_Kin);
  2072. dib7000p_write_word(state, 1537, P_Kout);
  2073. dib7000p_write_word(state, 1539, synchroMode);
  2074. dib7000p_write_word(state, 1540, (syncWord >> 16) & 0xffff);
  2075. dib7000p_write_word(state, 1541, syncWord & 0xffff);
  2076. dib7000p_write_word(state, 1543, syncSize);
  2077. dib7000p_write_word(state, 1544, dataOutRate);
  2078. dib7000p_write_word(state, 1554, 0);
  2079. return 0;
  2080. }
  2081. static void dib7090_enMpegMux(struct dib7000p_state *state, int onoff)
  2082. {
  2083. u16 reg_1287 = dib7000p_read_word(state, 1287);
  2084. switch (onoff) {
  2085. case 1:
  2086. reg_1287 &= ~(1<<7);
  2087. break;
  2088. case 0:
  2089. reg_1287 |= (1<<7);
  2090. break;
  2091. }
  2092. dib7000p_write_word(state, 1287, reg_1287);
  2093. }
  2094. static void dib7090_configMpegMux(struct dib7000p_state *state,
  2095. u16 pulseWidth, u16 enSerialMode, u16 enSerialClkDiv2)
  2096. {
  2097. dprintk("Enable Mpeg mux");
  2098. dib7090_enMpegMux(state, 0);
  2099. /* If the input mode is MPEG do not divide the serial clock */
  2100. if ((enSerialMode == 1) && (state->input_mode_mpeg == 1))
  2101. enSerialClkDiv2 = 0;
  2102. dib7000p_write_word(state, 1287, ((pulseWidth & 0x1f) << 2)
  2103. | ((enSerialMode & 0x1) << 1)
  2104. | (enSerialClkDiv2 & 0x1));
  2105. dib7090_enMpegMux(state, 1);
  2106. }
  2107. static void dib7090_setDibTxMux(struct dib7000p_state *state, int mode)
  2108. {
  2109. u16 reg_1288 = dib7000p_read_word(state, 1288) & ~(0x7 << 7);
  2110. switch (mode) {
  2111. case MPEG_ON_DIBTX:
  2112. dprintk("SET MPEG ON DIBSTREAM TX");
  2113. dib7090_cfg_DibTx(state, 8, 5, 0, 0, 0, 0);
  2114. reg_1288 |= (1<<9);
  2115. break;
  2116. case DIV_ON_DIBTX:
  2117. dprintk("SET DIV_OUT ON DIBSTREAM TX");
  2118. dib7090_cfg_DibTx(state, 5, 5, 0, 0, 0, 0);
  2119. reg_1288 |= (1<<8);
  2120. break;
  2121. case ADC_ON_DIBTX:
  2122. dprintk("SET ADC_OUT ON DIBSTREAM TX");
  2123. dib7090_cfg_DibTx(state, 20, 5, 10, 0, 0, 0);
  2124. reg_1288 |= (1<<7);
  2125. break;
  2126. default:
  2127. break;
  2128. }
  2129. dib7000p_write_word(state, 1288, reg_1288);
  2130. }
  2131. static void dib7090_setHostBusMux(struct dib7000p_state *state, int mode)
  2132. {
  2133. u16 reg_1288 = dib7000p_read_word(state, 1288) & ~(0x7 << 4);
  2134. switch (mode) {
  2135. case DEMOUT_ON_HOSTBUS:
  2136. dprintk("SET DEM OUT OLD INTERF ON HOST BUS");
  2137. dib7090_enMpegMux(state, 0);
  2138. reg_1288 |= (1<<6);
  2139. break;
  2140. case DIBTX_ON_HOSTBUS:
  2141. dprintk("SET DIBSTREAM TX ON HOST BUS");
  2142. dib7090_enMpegMux(state, 0);
  2143. reg_1288 |= (1<<5);
  2144. break;
  2145. case MPEG_ON_HOSTBUS:
  2146. dprintk("SET MPEG MUX ON HOST BUS");
  2147. reg_1288 |= (1<<4);
  2148. break;
  2149. default:
  2150. break;
  2151. }
  2152. dib7000p_write_word(state, 1288, reg_1288);
  2153. }
  2154. static int dib7090_set_diversity_in(struct dvb_frontend *fe, int onoff)
  2155. {
  2156. struct dib7000p_state *state = fe->demodulator_priv;
  2157. u16 reg_1287;
  2158. switch (onoff) {
  2159. case 0: /* only use the internal way - not the diversity input */
  2160. dprintk("%s mode OFF : by default Enable Mpeg INPUT", __func__);
  2161. dib7090_cfg_DibRx(state, 8, 5, 0, 0, 0, 8, 0);
  2162. /* Do not divide the serial clock of MPEG MUX */
  2163. /* in SERIAL MODE in case input mode MPEG is used */
  2164. reg_1287 = dib7000p_read_word(state, 1287);
  2165. /* enSerialClkDiv2 == 1 ? */
  2166. if ((reg_1287 & 0x1) == 1) {
  2167. /* force enSerialClkDiv2 = 0 */
  2168. reg_1287 &= ~0x1;
  2169. dib7000p_write_word(state, 1287, reg_1287);
  2170. }
  2171. state->input_mode_mpeg = 1;
  2172. break;
  2173. case 1: /* both ways */
  2174. case 2: /* only the diversity input */
  2175. dprintk("%s ON : Enable diversity INPUT", __func__);
  2176. dib7090_cfg_DibRx(state, 5, 5, 0, 0, 0, 0, 0);
  2177. state->input_mode_mpeg = 0;
  2178. break;
  2179. }
  2180. dib7000p_set_diversity_in(&state->demod, onoff);
  2181. return 0;
  2182. }
  2183. static int dib7090_set_output_mode(struct dvb_frontend *fe, int mode)
  2184. {
  2185. struct dib7000p_state *state = fe->demodulator_priv;
  2186. u16 outreg, smo_mode, fifo_threshold;
  2187. u8 prefer_mpeg_mux_use = 1;
  2188. int ret = 0;
  2189. dib7090_host_bus_drive(state, 1);
  2190. fifo_threshold = 1792;
  2191. smo_mode = (dib7000p_read_word(state, 235) & 0x0050) | (1 << 1);
  2192. outreg = dib7000p_read_word(state, 1286) & ~((1 << 10) | (0x7 << 6) | (1 << 1));
  2193. switch (mode) {
  2194. case OUTMODE_HIGH_Z:
  2195. outreg = 0;
  2196. break;
  2197. case OUTMODE_MPEG2_SERIAL:
  2198. if (prefer_mpeg_mux_use) {
  2199. dprintk("setting output mode TS_SERIAL using Mpeg Mux");
  2200. dib7090_configMpegMux(state, 3, 1, 1);
  2201. dib7090_setHostBusMux(state, MPEG_ON_HOSTBUS);
  2202. } else {/* Use Smooth block */
  2203. dprintk("setting output mode TS_SERIAL using Smooth bloc");
  2204. dib7090_setHostBusMux(state, DEMOUT_ON_HOSTBUS);
  2205. outreg |= (2<<6) | (0 << 1);
  2206. }
  2207. break;
  2208. case OUTMODE_MPEG2_PAR_GATED_CLK:
  2209. if (prefer_mpeg_mux_use) {
  2210. dprintk("setting output mode TS_PARALLEL_GATED using Mpeg Mux");
  2211. dib7090_configMpegMux(state, 2, 0, 0);
  2212. dib7090_setHostBusMux(state, MPEG_ON_HOSTBUS);
  2213. } else { /* Use Smooth block */
  2214. dprintk("setting output mode TS_PARALLEL_GATED using Smooth block");
  2215. dib7090_setHostBusMux(state, DEMOUT_ON_HOSTBUS);
  2216. outreg |= (0<<6);
  2217. }
  2218. break;
  2219. case OUTMODE_MPEG2_PAR_CONT_CLK: /* Using Smooth block only */
  2220. dprintk("setting output mode TS_PARALLEL_CONT using Smooth block");
  2221. dib7090_setHostBusMux(state, DEMOUT_ON_HOSTBUS);
  2222. outreg |= (1<<6);
  2223. break;
  2224. case OUTMODE_MPEG2_FIFO: /* Using Smooth block because not supported by new Mpeg Mux bloc */
  2225. dprintk("setting output mode TS_FIFO using Smooth block");
  2226. dib7090_setHostBusMux(state, DEMOUT_ON_HOSTBUS);
  2227. outreg |= (5<<6);
  2228. smo_mode |= (3 << 1);
  2229. fifo_threshold = 512;
  2230. break;
  2231. case OUTMODE_DIVERSITY:
  2232. dprintk("setting output mode MODE_DIVERSITY");
  2233. dib7090_setDibTxMux(state, DIV_ON_DIBTX);
  2234. dib7090_setHostBusMux(state, DIBTX_ON_HOSTBUS);
  2235. break;
  2236. case OUTMODE_ANALOG_ADC:
  2237. dprintk("setting output mode MODE_ANALOG_ADC");
  2238. dib7090_setDibTxMux(state, ADC_ON_DIBTX);
  2239. dib7090_setHostBusMux(state, DIBTX_ON_HOSTBUS);
  2240. break;
  2241. }
  2242. if (mode != OUTMODE_HIGH_Z)
  2243. outreg |= (1 << 10);
  2244. if (state->cfg.output_mpeg2_in_188_bytes)
  2245. smo_mode |= (1 << 5);
  2246. ret |= dib7000p_write_word(state, 235, smo_mode);
  2247. ret |= dib7000p_write_word(state, 236, fifo_threshold); /* synchronous fread */
  2248. ret |= dib7000p_write_word(state, 1286, outreg);
  2249. return ret;
  2250. }
  2251. static int dib7090_tuner_sleep(struct dvb_frontend *fe, int onoff)
  2252. {
  2253. struct dib7000p_state *state = fe->demodulator_priv;
  2254. u16 en_cur_state;
  2255. dprintk("sleep dib7090: %d", onoff);
  2256. en_cur_state = dib7000p_read_word(state, 1922);
  2257. if (en_cur_state > 0xff)
  2258. state->tuner_enable = en_cur_state;
  2259. if (onoff)
  2260. en_cur_state &= 0x00ff;
  2261. else {
  2262. if (state->tuner_enable != 0)
  2263. en_cur_state = state->tuner_enable;
  2264. }
  2265. dib7000p_write_word(state, 1922, en_cur_state);
  2266. return 0;
  2267. }
  2268. static int dib7090_get_adc_power(struct dvb_frontend *fe)
  2269. {
  2270. return dib7000p_get_adc_power(fe);
  2271. }
  2272. static int dib7090_slave_reset(struct dvb_frontend *fe)
  2273. {
  2274. struct dib7000p_state *state = fe->demodulator_priv;
  2275. u16 reg;
  2276. reg = dib7000p_read_word(state, 1794);
  2277. dib7000p_write_word(state, 1794, reg | (4 << 12));
  2278. dib7000p_write_word(state, 1032, 0xffff);
  2279. return 0;
  2280. }
  2281. static struct dvb_frontend_ops dib7000p_ops;
  2282. static struct dvb_frontend *dib7000p_init(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg)
  2283. {
  2284. struct dvb_frontend *demod;
  2285. struct dib7000p_state *st;
  2286. st = kzalloc(sizeof(struct dib7000p_state), GFP_KERNEL);
  2287. if (st == NULL)
  2288. return NULL;
  2289. memcpy(&st->cfg, cfg, sizeof(struct dib7000p_config));
  2290. st->i2c_adap = i2c_adap;
  2291. st->i2c_addr = i2c_addr;
  2292. st->gpio_val = cfg->gpio_val;
  2293. st->gpio_dir = cfg->gpio_dir;
  2294. /* Ensure the output mode remains at the previous default if it's
  2295. * not specifically set by the caller.
  2296. */
  2297. if ((st->cfg.output_mode != OUTMODE_MPEG2_SERIAL) && (st->cfg.output_mode != OUTMODE_MPEG2_PAR_GATED_CLK))
  2298. st->cfg.output_mode = OUTMODE_MPEG2_FIFO;
  2299. demod = &st->demod;
  2300. demod->demodulator_priv = st;
  2301. memcpy(&st->demod.ops, &dib7000p_ops, sizeof(struct dvb_frontend_ops));
  2302. mutex_init(&st->i2c_buffer_lock);
  2303. dib7000p_write_word(st, 1287, 0x0003); /* sram lead in, rdy */
  2304. if (dib7000p_identify(st) != 0)
  2305. goto error;
  2306. st->version = dib7000p_read_word(st, 897);
  2307. /* FIXME: make sure the dev.parent field is initialized, or else
  2308. request_firmware() will hit an OOPS (this should be moved somewhere
  2309. more common) */
  2310. st->i2c_master.gated_tuner_i2c_adap.dev.parent = i2c_adap->dev.parent;
  2311. dibx000_init_i2c_master(&st->i2c_master, DIB7000P, st->i2c_adap, st->i2c_addr);
  2312. /* init 7090 tuner adapter */
  2313. strncpy(st->dib7090_tuner_adap.name, "DiB7090 tuner interface", sizeof(st->dib7090_tuner_adap.name));
  2314. st->dib7090_tuner_adap.algo = &dib7090_tuner_xfer_algo;
  2315. st->dib7090_tuner_adap.algo_data = NULL;
  2316. st->dib7090_tuner_adap.dev.parent = st->i2c_adap->dev.parent;
  2317. i2c_set_adapdata(&st->dib7090_tuner_adap, st);
  2318. i2c_add_adapter(&st->dib7090_tuner_adap);
  2319. dib7000p_demod_reset(st);
  2320. dib7000p_reset_stats(demod);
  2321. if (st->version == SOC7090) {
  2322. dib7090_set_output_mode(demod, st->cfg.output_mode);
  2323. dib7090_set_diversity_in(demod, 0);
  2324. }
  2325. return demod;
  2326. error:
  2327. kfree(st);
  2328. return NULL;
  2329. }
  2330. void *dib7000p_attach(struct dib7000p_ops *ops)
  2331. {
  2332. if (!ops)
  2333. return NULL;
  2334. ops->slave_reset = dib7090_slave_reset;
  2335. ops->get_adc_power = dib7090_get_adc_power;
  2336. ops->dib7000pc_detection = dib7000pc_detection;
  2337. ops->get_i2c_tuner = dib7090_get_i2c_tuner;
  2338. ops->tuner_sleep = dib7090_tuner_sleep;
  2339. ops->init = dib7000p_init;
  2340. ops->set_agc1_min = dib7000p_set_agc1_min;
  2341. ops->set_gpio = dib7000p_set_gpio;
  2342. ops->i2c_enumeration = dib7000p_i2c_enumeration;
  2343. ops->pid_filter = dib7000p_pid_filter;
  2344. ops->pid_filter_ctrl = dib7000p_pid_filter_ctrl;
  2345. ops->get_i2c_master = dib7000p_get_i2c_master;
  2346. ops->update_pll = dib7000p_update_pll;
  2347. ops->ctrl_timf = dib7000p_ctrl_timf;
  2348. ops->get_agc_values = dib7000p_get_agc_values;
  2349. ops->set_wbd_ref = dib7000p_set_wbd_ref;
  2350. return ops;
  2351. }
  2352. EXPORT_SYMBOL(dib7000p_attach);
  2353. static struct dvb_frontend_ops dib7000p_ops = {
  2354. .delsys = { SYS_DVBT },
  2355. .info = {
  2356. .name = "DiBcom 7000PC",
  2357. .frequency_min = 44250000,
  2358. .frequency_max = 867250000,
  2359. .frequency_stepsize = 62500,
  2360. .caps = FE_CAN_INVERSION_AUTO |
  2361. FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  2362. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  2363. FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
  2364. FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO | FE_CAN_RECOVER | FE_CAN_HIERARCHY_AUTO,
  2365. },
  2366. .release = dib7000p_release,
  2367. .init = dib7000p_wakeup,
  2368. .sleep = dib7000p_sleep,
  2369. .set_frontend = dib7000p_set_frontend,
  2370. .get_tune_settings = dib7000p_fe_get_tune_settings,
  2371. .get_frontend = dib7000p_get_frontend,
  2372. .read_status = dib7000p_read_status,
  2373. .read_ber = dib7000p_read_ber,
  2374. .read_signal_strength = dib7000p_read_signal_strength,
  2375. .read_snr = dib7000p_read_snr,
  2376. .read_ucblocks = dib7000p_read_unc_blocks,
  2377. };
  2378. MODULE_AUTHOR("Olivier Grenie <ogrenie@dibcom.fr>");
  2379. MODULE_AUTHOR("Patrick Boettcher <pboettcher@dibcom.fr>");
  2380. MODULE_DESCRIPTION("Driver for the DiBcom 7000PC COFDM demodulator");
  2381. MODULE_LICENSE("GPL");