dib7000p.c 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840
  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, enum fe_status stat);
  1299. static int dib7000p_read_status(struct dvb_frontend *fe, enum fe_status *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)
  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, enum fe_status stat)
  1572. {
  1573. struct dib7000p_state *state = demod->demodulator_priv;
  1574. struct dtv_frontend_properties *c = &demod->dtv_property_cache;
  1575. int show_per_stats = 0;
  1576. u32 time_us = 0, val, snr;
  1577. u64 blocks, ucb;
  1578. s32 db;
  1579. u16 strength;
  1580. /* Get Signal strength */
  1581. dib7000p_read_signal_strength(demod, &strength);
  1582. val = strength;
  1583. db = interpolate_value(val,
  1584. strength_to_db_table,
  1585. ARRAY_SIZE(strength_to_db_table)) - DB_OFFSET;
  1586. c->strength.stat[0].svalue = db;
  1587. /* UCB/BER/CNR measures require lock */
  1588. if (!(stat & FE_HAS_LOCK)) {
  1589. c->cnr.len = 1;
  1590. c->block_count.len = 1;
  1591. c->block_error.len = 1;
  1592. c->post_bit_error.len = 1;
  1593. c->post_bit_count.len = 1;
  1594. c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1595. c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1596. c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1597. c->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1598. c->block_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  1599. return 0;
  1600. }
  1601. /* Check if time for stats was elapsed */
  1602. if (time_after(jiffies, state->per_jiffies_stats)) {
  1603. state->per_jiffies_stats = jiffies + msecs_to_jiffies(1000);
  1604. /* Get SNR */
  1605. snr = dib7000p_get_snr(demod);
  1606. if (snr)
  1607. snr = (1000L * snr) >> 24;
  1608. else
  1609. snr = 0;
  1610. c->cnr.stat[0].svalue = snr;
  1611. c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
  1612. /* Get UCB measures */
  1613. dib7000p_read_unc_blocks(demod, &val);
  1614. ucb = val - state->old_ucb;
  1615. if (val < state->old_ucb)
  1616. ucb += 0x100000000LL;
  1617. c->block_error.stat[0].scale = FE_SCALE_COUNTER;
  1618. c->block_error.stat[0].uvalue = ucb;
  1619. /* Estimate the number of packets based on bitrate */
  1620. if (!time_us)
  1621. time_us = dib7000p_get_time_us(demod);
  1622. if (time_us) {
  1623. blocks = 1250000ULL * 1000000ULL;
  1624. do_div(blocks, time_us * 8 * 204);
  1625. c->block_count.stat[0].scale = FE_SCALE_COUNTER;
  1626. c->block_count.stat[0].uvalue += blocks;
  1627. }
  1628. show_per_stats = 1;
  1629. }
  1630. /* Get post-BER measures */
  1631. if (time_after(jiffies, state->ber_jiffies_stats)) {
  1632. time_us = dib7000p_get_time_us(demod);
  1633. state->ber_jiffies_stats = jiffies + msecs_to_jiffies((time_us + 500) / 1000);
  1634. dprintk("Next all layers stats available in %u us.", time_us);
  1635. dib7000p_read_ber(demod, &val);
  1636. c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
  1637. c->post_bit_error.stat[0].uvalue += val;
  1638. c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
  1639. c->post_bit_count.stat[0].uvalue += 100000000;
  1640. }
  1641. /* Get PER measures */
  1642. if (show_per_stats) {
  1643. dib7000p_read_unc_blocks(demod, &val);
  1644. c->block_error.stat[0].scale = FE_SCALE_COUNTER;
  1645. c->block_error.stat[0].uvalue += val;
  1646. time_us = dib7000p_get_time_us(demod);
  1647. if (time_us) {
  1648. blocks = 1250000ULL * 1000000ULL;
  1649. do_div(blocks, time_us * 8 * 204);
  1650. c->block_count.stat[0].scale = FE_SCALE_COUNTER;
  1651. c->block_count.stat[0].uvalue += blocks;
  1652. }
  1653. }
  1654. return 0;
  1655. }
  1656. static int dib7000p_fe_get_tune_settings(struct dvb_frontend *fe, struct dvb_frontend_tune_settings *tune)
  1657. {
  1658. tune->min_delay_ms = 1000;
  1659. return 0;
  1660. }
  1661. static void dib7000p_release(struct dvb_frontend *demod)
  1662. {
  1663. struct dib7000p_state *st = demod->demodulator_priv;
  1664. dibx000_exit_i2c_master(&st->i2c_master);
  1665. i2c_del_adapter(&st->dib7090_tuner_adap);
  1666. kfree(st);
  1667. }
  1668. static int dib7000pc_detection(struct i2c_adapter *i2c_adap)
  1669. {
  1670. u8 *tx, *rx;
  1671. struct i2c_msg msg[2] = {
  1672. {.addr = 18 >> 1, .flags = 0, .len = 2},
  1673. {.addr = 18 >> 1, .flags = I2C_M_RD, .len = 2},
  1674. };
  1675. int ret = 0;
  1676. tx = kzalloc(2*sizeof(u8), GFP_KERNEL);
  1677. if (!tx)
  1678. return -ENOMEM;
  1679. rx = kzalloc(2*sizeof(u8), GFP_KERNEL);
  1680. if (!rx) {
  1681. ret = -ENOMEM;
  1682. goto rx_memory_error;
  1683. }
  1684. msg[0].buf = tx;
  1685. msg[1].buf = rx;
  1686. tx[0] = 0x03;
  1687. tx[1] = 0x00;
  1688. if (i2c_transfer(i2c_adap, msg, 2) == 2)
  1689. if (rx[0] == 0x01 && rx[1] == 0xb3) {
  1690. dprintk("-D- DiB7000PC detected");
  1691. return 1;
  1692. }
  1693. msg[0].addr = msg[1].addr = 0x40;
  1694. if (i2c_transfer(i2c_adap, msg, 2) == 2)
  1695. if (rx[0] == 0x01 && rx[1] == 0xb3) {
  1696. dprintk("-D- DiB7000PC detected");
  1697. return 1;
  1698. }
  1699. dprintk("-D- DiB7000PC not detected");
  1700. kfree(rx);
  1701. rx_memory_error:
  1702. kfree(tx);
  1703. return ret;
  1704. }
  1705. static struct i2c_adapter *dib7000p_get_i2c_master(struct dvb_frontend *demod, enum dibx000_i2c_interface intf, int gating)
  1706. {
  1707. struct dib7000p_state *st = demod->demodulator_priv;
  1708. return dibx000_get_i2c_adapter(&st->i2c_master, intf, gating);
  1709. }
  1710. static int dib7000p_pid_filter_ctrl(struct dvb_frontend *fe, u8 onoff)
  1711. {
  1712. struct dib7000p_state *state = fe->demodulator_priv;
  1713. u16 val = dib7000p_read_word(state, 235) & 0xffef;
  1714. val |= (onoff & 0x1) << 4;
  1715. dprintk("PID filter enabled %d", onoff);
  1716. return dib7000p_write_word(state, 235, val);
  1717. }
  1718. static int dib7000p_pid_filter(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff)
  1719. {
  1720. struct dib7000p_state *state = fe->demodulator_priv;
  1721. dprintk("PID filter: index %x, PID %d, OnOff %d", id, pid, onoff);
  1722. return dib7000p_write_word(state, 241 + id, onoff ? (1 << 13) | pid : 0);
  1723. }
  1724. static int dib7000p_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, struct dib7000p_config cfg[])
  1725. {
  1726. struct dib7000p_state *dpst;
  1727. int k = 0;
  1728. u8 new_addr = 0;
  1729. dpst = kzalloc(sizeof(struct dib7000p_state), GFP_KERNEL);
  1730. if (!dpst)
  1731. return -ENOMEM;
  1732. dpst->i2c_adap = i2c;
  1733. mutex_init(&dpst->i2c_buffer_lock);
  1734. for (k = no_of_demods - 1; k >= 0; k--) {
  1735. dpst->cfg = cfg[k];
  1736. /* designated i2c address */
  1737. if (cfg[k].default_i2c_addr != 0)
  1738. new_addr = cfg[k].default_i2c_addr + (k << 1);
  1739. else
  1740. new_addr = (0x40 + k) << 1;
  1741. dpst->i2c_addr = new_addr;
  1742. dib7000p_write_word(dpst, 1287, 0x0003); /* sram lead in, rdy */
  1743. if (dib7000p_identify(dpst) != 0) {
  1744. dpst->i2c_addr = default_addr;
  1745. dib7000p_write_word(dpst, 1287, 0x0003); /* sram lead in, rdy */
  1746. if (dib7000p_identify(dpst) != 0) {
  1747. dprintk("DiB7000P #%d: not identified\n", k);
  1748. kfree(dpst);
  1749. return -EIO;
  1750. }
  1751. }
  1752. /* start diversity to pull_down div_str - just for i2c-enumeration */
  1753. dib7000p_set_output_mode(dpst, OUTMODE_DIVERSITY);
  1754. /* set new i2c address and force divstart */
  1755. dib7000p_write_word(dpst, 1285, (new_addr << 2) | 0x2);
  1756. dprintk("IC %d initialized (to i2c_address 0x%x)", k, new_addr);
  1757. }
  1758. for (k = 0; k < no_of_demods; k++) {
  1759. dpst->cfg = cfg[k];
  1760. if (cfg[k].default_i2c_addr != 0)
  1761. dpst->i2c_addr = (cfg[k].default_i2c_addr + k) << 1;
  1762. else
  1763. dpst->i2c_addr = (0x40 + k) << 1;
  1764. // unforce divstr
  1765. dib7000p_write_word(dpst, 1285, dpst->i2c_addr << 2);
  1766. /* deactivate div - it was just for i2c-enumeration */
  1767. dib7000p_set_output_mode(dpst, OUTMODE_HIGH_Z);
  1768. }
  1769. kfree(dpst);
  1770. return 0;
  1771. }
  1772. static const s32 lut_1000ln_mant[] = {
  1773. 6908, 6956, 7003, 7047, 7090, 7131, 7170, 7208, 7244, 7279, 7313, 7346, 7377, 7408, 7438, 7467, 7495, 7523, 7549, 7575, 7600
  1774. };
  1775. static s32 dib7000p_get_adc_power(struct dvb_frontend *fe)
  1776. {
  1777. struct dib7000p_state *state = fe->demodulator_priv;
  1778. u32 tmp_val = 0, exp = 0, mant = 0;
  1779. s32 pow_i;
  1780. u16 buf[2];
  1781. u8 ix = 0;
  1782. buf[0] = dib7000p_read_word(state, 0x184);
  1783. buf[1] = dib7000p_read_word(state, 0x185);
  1784. pow_i = (buf[0] << 16) | buf[1];
  1785. dprintk("raw pow_i = %d", pow_i);
  1786. tmp_val = pow_i;
  1787. while (tmp_val >>= 1)
  1788. exp++;
  1789. mant = (pow_i * 1000 / (1 << exp));
  1790. dprintk(" mant = %d exp = %d", mant / 1000, exp);
  1791. ix = (u8) ((mant - 1000) / 100); /* index of the LUT */
  1792. dprintk(" ix = %d", ix);
  1793. pow_i = (lut_1000ln_mant[ix] + 693 * (exp - 20) - 6908);
  1794. pow_i = (pow_i << 8) / 1000;
  1795. dprintk(" pow_i = %d", pow_i);
  1796. return pow_i;
  1797. }
  1798. static int map_addr_to_serpar_number(struct i2c_msg *msg)
  1799. {
  1800. if ((msg->buf[0] <= 15))
  1801. msg->buf[0] -= 1;
  1802. else if (msg->buf[0] == 17)
  1803. msg->buf[0] = 15;
  1804. else if (msg->buf[0] == 16)
  1805. msg->buf[0] = 17;
  1806. else if (msg->buf[0] == 19)
  1807. msg->buf[0] = 16;
  1808. else if (msg->buf[0] >= 21 && msg->buf[0] <= 25)
  1809. msg->buf[0] -= 3;
  1810. else if (msg->buf[0] == 28)
  1811. msg->buf[0] = 23;
  1812. else
  1813. return -EINVAL;
  1814. return 0;
  1815. }
  1816. static int w7090p_tuner_write_serpar(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num)
  1817. {
  1818. struct dib7000p_state *state = i2c_get_adapdata(i2c_adap);
  1819. u8 n_overflow = 1;
  1820. u16 i = 1000;
  1821. u16 serpar_num = msg[0].buf[0];
  1822. while (n_overflow == 1 && i) {
  1823. n_overflow = (dib7000p_read_word(state, 1984) >> 1) & 0x1;
  1824. i--;
  1825. if (i == 0)
  1826. dprintk("Tuner ITF: write busy (overflow)");
  1827. }
  1828. dib7000p_write_word(state, 1985, (1 << 6) | (serpar_num & 0x3f));
  1829. dib7000p_write_word(state, 1986, (msg[0].buf[1] << 8) | msg[0].buf[2]);
  1830. return num;
  1831. }
  1832. static int w7090p_tuner_read_serpar(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num)
  1833. {
  1834. struct dib7000p_state *state = i2c_get_adapdata(i2c_adap);
  1835. u8 n_overflow = 1, n_empty = 1;
  1836. u16 i = 1000;
  1837. u16 serpar_num = msg[0].buf[0];
  1838. u16 read_word;
  1839. while (n_overflow == 1 && i) {
  1840. n_overflow = (dib7000p_read_word(state, 1984) >> 1) & 0x1;
  1841. i--;
  1842. if (i == 0)
  1843. dprintk("TunerITF: read busy (overflow)");
  1844. }
  1845. dib7000p_write_word(state, 1985, (0 << 6) | (serpar_num & 0x3f));
  1846. i = 1000;
  1847. while (n_empty == 1 && i) {
  1848. n_empty = dib7000p_read_word(state, 1984) & 0x1;
  1849. i--;
  1850. if (i == 0)
  1851. dprintk("TunerITF: read busy (empty)");
  1852. }
  1853. read_word = dib7000p_read_word(state, 1987);
  1854. msg[1].buf[0] = (read_word >> 8) & 0xff;
  1855. msg[1].buf[1] = (read_word) & 0xff;
  1856. return num;
  1857. }
  1858. static int w7090p_tuner_rw_serpar(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num)
  1859. {
  1860. 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... */
  1861. if (num == 1) { /* write */
  1862. return w7090p_tuner_write_serpar(i2c_adap, msg, 1);
  1863. } else { /* read */
  1864. return w7090p_tuner_read_serpar(i2c_adap, msg, 2);
  1865. }
  1866. }
  1867. return num;
  1868. }
  1869. static int dib7090p_rw_on_apb(struct i2c_adapter *i2c_adap,
  1870. struct i2c_msg msg[], int num, u16 apb_address)
  1871. {
  1872. struct dib7000p_state *state = i2c_get_adapdata(i2c_adap);
  1873. u16 word;
  1874. if (num == 1) { /* write */
  1875. dib7000p_write_word(state, apb_address, ((msg[0].buf[1] << 8) | (msg[0].buf[2])));
  1876. } else {
  1877. word = dib7000p_read_word(state, apb_address);
  1878. msg[1].buf[0] = (word >> 8) & 0xff;
  1879. msg[1].buf[1] = (word) & 0xff;
  1880. }
  1881. return num;
  1882. }
  1883. static int dib7090_tuner_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num)
  1884. {
  1885. struct dib7000p_state *state = i2c_get_adapdata(i2c_adap);
  1886. u16 apb_address = 0, word;
  1887. int i = 0;
  1888. switch (msg[0].buf[0]) {
  1889. case 0x12:
  1890. apb_address = 1920;
  1891. break;
  1892. case 0x14:
  1893. apb_address = 1921;
  1894. break;
  1895. case 0x24:
  1896. apb_address = 1922;
  1897. break;
  1898. case 0x1a:
  1899. apb_address = 1923;
  1900. break;
  1901. case 0x22:
  1902. apb_address = 1924;
  1903. break;
  1904. case 0x33:
  1905. apb_address = 1926;
  1906. break;
  1907. case 0x34:
  1908. apb_address = 1927;
  1909. break;
  1910. case 0x35:
  1911. apb_address = 1928;
  1912. break;
  1913. case 0x36:
  1914. apb_address = 1929;
  1915. break;
  1916. case 0x37:
  1917. apb_address = 1930;
  1918. break;
  1919. case 0x38:
  1920. apb_address = 1931;
  1921. break;
  1922. case 0x39:
  1923. apb_address = 1932;
  1924. break;
  1925. case 0x2a:
  1926. apb_address = 1935;
  1927. break;
  1928. case 0x2b:
  1929. apb_address = 1936;
  1930. break;
  1931. case 0x2c:
  1932. apb_address = 1937;
  1933. break;
  1934. case 0x2d:
  1935. apb_address = 1938;
  1936. break;
  1937. case 0x2e:
  1938. apb_address = 1939;
  1939. break;
  1940. case 0x2f:
  1941. apb_address = 1940;
  1942. break;
  1943. case 0x30:
  1944. apb_address = 1941;
  1945. break;
  1946. case 0x31:
  1947. apb_address = 1942;
  1948. break;
  1949. case 0x32:
  1950. apb_address = 1943;
  1951. break;
  1952. case 0x3e:
  1953. apb_address = 1944;
  1954. break;
  1955. case 0x3f:
  1956. apb_address = 1945;
  1957. break;
  1958. case 0x40:
  1959. apb_address = 1948;
  1960. break;
  1961. case 0x25:
  1962. apb_address = 914;
  1963. break;
  1964. case 0x26:
  1965. apb_address = 915;
  1966. break;
  1967. case 0x27:
  1968. apb_address = 917;
  1969. break;
  1970. case 0x28:
  1971. apb_address = 916;
  1972. break;
  1973. case 0x1d:
  1974. i = ((dib7000p_read_word(state, 72) >> 12) & 0x3);
  1975. word = dib7000p_read_word(state, 384 + i);
  1976. msg[1].buf[0] = (word >> 8) & 0xff;
  1977. msg[1].buf[1] = (word) & 0xff;
  1978. return num;
  1979. case 0x1f:
  1980. if (num == 1) { /* write */
  1981. word = (u16) ((msg[0].buf[1] << 8) | msg[0].buf[2]);
  1982. word &= 0x3;
  1983. word = (dib7000p_read_word(state, 72) & ~(3 << 12)) | (word << 12);
  1984. dib7000p_write_word(state, 72, word); /* Set the proper input */
  1985. return num;
  1986. }
  1987. }
  1988. if (apb_address != 0) /* R/W acces via APB */
  1989. return dib7090p_rw_on_apb(i2c_adap, msg, num, apb_address);
  1990. else /* R/W access via SERPAR */
  1991. return w7090p_tuner_rw_serpar(i2c_adap, msg, num);
  1992. return 0;
  1993. }
  1994. static u32 dib7000p_i2c_func(struct i2c_adapter *adapter)
  1995. {
  1996. return I2C_FUNC_I2C;
  1997. }
  1998. static struct i2c_algorithm dib7090_tuner_xfer_algo = {
  1999. .master_xfer = dib7090_tuner_xfer,
  2000. .functionality = dib7000p_i2c_func,
  2001. };
  2002. static struct i2c_adapter *dib7090_get_i2c_tuner(struct dvb_frontend *fe)
  2003. {
  2004. struct dib7000p_state *st = fe->demodulator_priv;
  2005. return &st->dib7090_tuner_adap;
  2006. }
  2007. static int dib7090_host_bus_drive(struct dib7000p_state *state, u8 drive)
  2008. {
  2009. u16 reg;
  2010. /* drive host bus 2, 3, 4 */
  2011. reg = dib7000p_read_word(state, 1798) & ~((0x7) | (0x7 << 6) | (0x7 << 12));
  2012. reg |= (drive << 12) | (drive << 6) | drive;
  2013. dib7000p_write_word(state, 1798, reg);
  2014. /* drive host bus 5,6 */
  2015. reg = dib7000p_read_word(state, 1799) & ~((0x7 << 2) | (0x7 << 8));
  2016. reg |= (drive << 8) | (drive << 2);
  2017. dib7000p_write_word(state, 1799, reg);
  2018. /* drive host bus 7, 8, 9 */
  2019. reg = dib7000p_read_word(state, 1800) & ~((0x7) | (0x7 << 6) | (0x7 << 12));
  2020. reg |= (drive << 12) | (drive << 6) | drive;
  2021. dib7000p_write_word(state, 1800, reg);
  2022. /* drive host bus 10, 11 */
  2023. reg = dib7000p_read_word(state, 1801) & ~((0x7 << 2) | (0x7 << 8));
  2024. reg |= (drive << 8) | (drive << 2);
  2025. dib7000p_write_word(state, 1801, reg);
  2026. /* drive host bus 12, 13, 14 */
  2027. reg = dib7000p_read_word(state, 1802) & ~((0x7) | (0x7 << 6) | (0x7 << 12));
  2028. reg |= (drive << 12) | (drive << 6) | drive;
  2029. dib7000p_write_word(state, 1802, reg);
  2030. return 0;
  2031. }
  2032. static u32 dib7090_calcSyncFreq(u32 P_Kin, u32 P_Kout, u32 insertExtSynchro, u32 syncSize)
  2033. {
  2034. u32 quantif = 3;
  2035. u32 nom = (insertExtSynchro * P_Kin + syncSize);
  2036. u32 denom = P_Kout;
  2037. u32 syncFreq = ((nom << quantif) / denom);
  2038. if ((syncFreq & ((1 << quantif) - 1)) != 0)
  2039. syncFreq = (syncFreq >> quantif) + 1;
  2040. else
  2041. syncFreq = (syncFreq >> quantif);
  2042. if (syncFreq != 0)
  2043. syncFreq = syncFreq - 1;
  2044. return syncFreq;
  2045. }
  2046. static int dib7090_cfg_DibTx(struct dib7000p_state *state, u32 P_Kin, u32 P_Kout, u32 insertExtSynchro, u32 synchroMode, u32 syncWord, u32 syncSize)
  2047. {
  2048. dprintk("Configure DibStream Tx");
  2049. dib7000p_write_word(state, 1615, 1);
  2050. dib7000p_write_word(state, 1603, P_Kin);
  2051. dib7000p_write_word(state, 1605, P_Kout);
  2052. dib7000p_write_word(state, 1606, insertExtSynchro);
  2053. dib7000p_write_word(state, 1608, synchroMode);
  2054. dib7000p_write_word(state, 1609, (syncWord >> 16) & 0xffff);
  2055. dib7000p_write_word(state, 1610, syncWord & 0xffff);
  2056. dib7000p_write_word(state, 1612, syncSize);
  2057. dib7000p_write_word(state, 1615, 0);
  2058. return 0;
  2059. }
  2060. static int dib7090_cfg_DibRx(struct dib7000p_state *state, u32 P_Kin, u32 P_Kout, u32 synchroMode, u32 insertExtSynchro, u32 syncWord, u32 syncSize,
  2061. u32 dataOutRate)
  2062. {
  2063. u32 syncFreq;
  2064. dprintk("Configure DibStream Rx");
  2065. if ((P_Kin != 0) && (P_Kout != 0)) {
  2066. syncFreq = dib7090_calcSyncFreq(P_Kin, P_Kout, insertExtSynchro, syncSize);
  2067. dib7000p_write_word(state, 1542, syncFreq);
  2068. }
  2069. dib7000p_write_word(state, 1554, 1);
  2070. dib7000p_write_word(state, 1536, P_Kin);
  2071. dib7000p_write_word(state, 1537, P_Kout);
  2072. dib7000p_write_word(state, 1539, synchroMode);
  2073. dib7000p_write_word(state, 1540, (syncWord >> 16) & 0xffff);
  2074. dib7000p_write_word(state, 1541, syncWord & 0xffff);
  2075. dib7000p_write_word(state, 1543, syncSize);
  2076. dib7000p_write_word(state, 1544, dataOutRate);
  2077. dib7000p_write_word(state, 1554, 0);
  2078. return 0;
  2079. }
  2080. static void dib7090_enMpegMux(struct dib7000p_state *state, int onoff)
  2081. {
  2082. u16 reg_1287 = dib7000p_read_word(state, 1287);
  2083. switch (onoff) {
  2084. case 1:
  2085. reg_1287 &= ~(1<<7);
  2086. break;
  2087. case 0:
  2088. reg_1287 |= (1<<7);
  2089. break;
  2090. }
  2091. dib7000p_write_word(state, 1287, reg_1287);
  2092. }
  2093. static void dib7090_configMpegMux(struct dib7000p_state *state,
  2094. u16 pulseWidth, u16 enSerialMode, u16 enSerialClkDiv2)
  2095. {
  2096. dprintk("Enable Mpeg mux");
  2097. dib7090_enMpegMux(state, 0);
  2098. /* If the input mode is MPEG do not divide the serial clock */
  2099. if ((enSerialMode == 1) && (state->input_mode_mpeg == 1))
  2100. enSerialClkDiv2 = 0;
  2101. dib7000p_write_word(state, 1287, ((pulseWidth & 0x1f) << 2)
  2102. | ((enSerialMode & 0x1) << 1)
  2103. | (enSerialClkDiv2 & 0x1));
  2104. dib7090_enMpegMux(state, 1);
  2105. }
  2106. static void dib7090_setDibTxMux(struct dib7000p_state *state, int mode)
  2107. {
  2108. u16 reg_1288 = dib7000p_read_word(state, 1288) & ~(0x7 << 7);
  2109. switch (mode) {
  2110. case MPEG_ON_DIBTX:
  2111. dprintk("SET MPEG ON DIBSTREAM TX");
  2112. dib7090_cfg_DibTx(state, 8, 5, 0, 0, 0, 0);
  2113. reg_1288 |= (1<<9);
  2114. break;
  2115. case DIV_ON_DIBTX:
  2116. dprintk("SET DIV_OUT ON DIBSTREAM TX");
  2117. dib7090_cfg_DibTx(state, 5, 5, 0, 0, 0, 0);
  2118. reg_1288 |= (1<<8);
  2119. break;
  2120. case ADC_ON_DIBTX:
  2121. dprintk("SET ADC_OUT ON DIBSTREAM TX");
  2122. dib7090_cfg_DibTx(state, 20, 5, 10, 0, 0, 0);
  2123. reg_1288 |= (1<<7);
  2124. break;
  2125. default:
  2126. break;
  2127. }
  2128. dib7000p_write_word(state, 1288, reg_1288);
  2129. }
  2130. static void dib7090_setHostBusMux(struct dib7000p_state *state, int mode)
  2131. {
  2132. u16 reg_1288 = dib7000p_read_word(state, 1288) & ~(0x7 << 4);
  2133. switch (mode) {
  2134. case DEMOUT_ON_HOSTBUS:
  2135. dprintk("SET DEM OUT OLD INTERF ON HOST BUS");
  2136. dib7090_enMpegMux(state, 0);
  2137. reg_1288 |= (1<<6);
  2138. break;
  2139. case DIBTX_ON_HOSTBUS:
  2140. dprintk("SET DIBSTREAM TX ON HOST BUS");
  2141. dib7090_enMpegMux(state, 0);
  2142. reg_1288 |= (1<<5);
  2143. break;
  2144. case MPEG_ON_HOSTBUS:
  2145. dprintk("SET MPEG MUX ON HOST BUS");
  2146. reg_1288 |= (1<<4);
  2147. break;
  2148. default:
  2149. break;
  2150. }
  2151. dib7000p_write_word(state, 1288, reg_1288);
  2152. }
  2153. static int dib7090_set_diversity_in(struct dvb_frontend *fe, int onoff)
  2154. {
  2155. struct dib7000p_state *state = fe->demodulator_priv;
  2156. u16 reg_1287;
  2157. switch (onoff) {
  2158. case 0: /* only use the internal way - not the diversity input */
  2159. dprintk("%s mode OFF : by default Enable Mpeg INPUT", __func__);
  2160. dib7090_cfg_DibRx(state, 8, 5, 0, 0, 0, 8, 0);
  2161. /* Do not divide the serial clock of MPEG MUX */
  2162. /* in SERIAL MODE in case input mode MPEG is used */
  2163. reg_1287 = dib7000p_read_word(state, 1287);
  2164. /* enSerialClkDiv2 == 1 ? */
  2165. if ((reg_1287 & 0x1) == 1) {
  2166. /* force enSerialClkDiv2 = 0 */
  2167. reg_1287 &= ~0x1;
  2168. dib7000p_write_word(state, 1287, reg_1287);
  2169. }
  2170. state->input_mode_mpeg = 1;
  2171. break;
  2172. case 1: /* both ways */
  2173. case 2: /* only the diversity input */
  2174. dprintk("%s ON : Enable diversity INPUT", __func__);
  2175. dib7090_cfg_DibRx(state, 5, 5, 0, 0, 0, 0, 0);
  2176. state->input_mode_mpeg = 0;
  2177. break;
  2178. }
  2179. dib7000p_set_diversity_in(&state->demod, onoff);
  2180. return 0;
  2181. }
  2182. static int dib7090_set_output_mode(struct dvb_frontend *fe, int mode)
  2183. {
  2184. struct dib7000p_state *state = fe->demodulator_priv;
  2185. u16 outreg, smo_mode, fifo_threshold;
  2186. u8 prefer_mpeg_mux_use = 1;
  2187. int ret = 0;
  2188. dib7090_host_bus_drive(state, 1);
  2189. fifo_threshold = 1792;
  2190. smo_mode = (dib7000p_read_word(state, 235) & 0x0050) | (1 << 1);
  2191. outreg = dib7000p_read_word(state, 1286) & ~((1 << 10) | (0x7 << 6) | (1 << 1));
  2192. switch (mode) {
  2193. case OUTMODE_HIGH_Z:
  2194. outreg = 0;
  2195. break;
  2196. case OUTMODE_MPEG2_SERIAL:
  2197. if (prefer_mpeg_mux_use) {
  2198. dprintk("setting output mode TS_SERIAL using Mpeg Mux");
  2199. dib7090_configMpegMux(state, 3, 1, 1);
  2200. dib7090_setHostBusMux(state, MPEG_ON_HOSTBUS);
  2201. } else {/* Use Smooth block */
  2202. dprintk("setting output mode TS_SERIAL using Smooth bloc");
  2203. dib7090_setHostBusMux(state, DEMOUT_ON_HOSTBUS);
  2204. outreg |= (2<<6) | (0 << 1);
  2205. }
  2206. break;
  2207. case OUTMODE_MPEG2_PAR_GATED_CLK:
  2208. if (prefer_mpeg_mux_use) {
  2209. dprintk("setting output mode TS_PARALLEL_GATED using Mpeg Mux");
  2210. dib7090_configMpegMux(state, 2, 0, 0);
  2211. dib7090_setHostBusMux(state, MPEG_ON_HOSTBUS);
  2212. } else { /* Use Smooth block */
  2213. dprintk("setting output mode TS_PARALLEL_GATED using Smooth block");
  2214. dib7090_setHostBusMux(state, DEMOUT_ON_HOSTBUS);
  2215. outreg |= (0<<6);
  2216. }
  2217. break;
  2218. case OUTMODE_MPEG2_PAR_CONT_CLK: /* Using Smooth block only */
  2219. dprintk("setting output mode TS_PARALLEL_CONT using Smooth block");
  2220. dib7090_setHostBusMux(state, DEMOUT_ON_HOSTBUS);
  2221. outreg |= (1<<6);
  2222. break;
  2223. case OUTMODE_MPEG2_FIFO: /* Using Smooth block because not supported by new Mpeg Mux bloc */
  2224. dprintk("setting output mode TS_FIFO using Smooth block");
  2225. dib7090_setHostBusMux(state, DEMOUT_ON_HOSTBUS);
  2226. outreg |= (5<<6);
  2227. smo_mode |= (3 << 1);
  2228. fifo_threshold = 512;
  2229. break;
  2230. case OUTMODE_DIVERSITY:
  2231. dprintk("setting output mode MODE_DIVERSITY");
  2232. dib7090_setDibTxMux(state, DIV_ON_DIBTX);
  2233. dib7090_setHostBusMux(state, DIBTX_ON_HOSTBUS);
  2234. break;
  2235. case OUTMODE_ANALOG_ADC:
  2236. dprintk("setting output mode MODE_ANALOG_ADC");
  2237. dib7090_setDibTxMux(state, ADC_ON_DIBTX);
  2238. dib7090_setHostBusMux(state, DIBTX_ON_HOSTBUS);
  2239. break;
  2240. }
  2241. if (mode != OUTMODE_HIGH_Z)
  2242. outreg |= (1 << 10);
  2243. if (state->cfg.output_mpeg2_in_188_bytes)
  2244. smo_mode |= (1 << 5);
  2245. ret |= dib7000p_write_word(state, 235, smo_mode);
  2246. ret |= dib7000p_write_word(state, 236, fifo_threshold); /* synchronous fread */
  2247. ret |= dib7000p_write_word(state, 1286, outreg);
  2248. return ret;
  2249. }
  2250. static int dib7090_tuner_sleep(struct dvb_frontend *fe, int onoff)
  2251. {
  2252. struct dib7000p_state *state = fe->demodulator_priv;
  2253. u16 en_cur_state;
  2254. dprintk("sleep dib7090: %d", onoff);
  2255. en_cur_state = dib7000p_read_word(state, 1922);
  2256. if (en_cur_state > 0xff)
  2257. state->tuner_enable = en_cur_state;
  2258. if (onoff)
  2259. en_cur_state &= 0x00ff;
  2260. else {
  2261. if (state->tuner_enable != 0)
  2262. en_cur_state = state->tuner_enable;
  2263. }
  2264. dib7000p_write_word(state, 1922, en_cur_state);
  2265. return 0;
  2266. }
  2267. static int dib7090_get_adc_power(struct dvb_frontend *fe)
  2268. {
  2269. return dib7000p_get_adc_power(fe);
  2270. }
  2271. static int dib7090_slave_reset(struct dvb_frontend *fe)
  2272. {
  2273. struct dib7000p_state *state = fe->demodulator_priv;
  2274. u16 reg;
  2275. reg = dib7000p_read_word(state, 1794);
  2276. dib7000p_write_word(state, 1794, reg | (4 << 12));
  2277. dib7000p_write_word(state, 1032, 0xffff);
  2278. return 0;
  2279. }
  2280. static struct dvb_frontend_ops dib7000p_ops;
  2281. static struct dvb_frontend *dib7000p_init(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg)
  2282. {
  2283. struct dvb_frontend *demod;
  2284. struct dib7000p_state *st;
  2285. st = kzalloc(sizeof(struct dib7000p_state), GFP_KERNEL);
  2286. if (st == NULL)
  2287. return NULL;
  2288. memcpy(&st->cfg, cfg, sizeof(struct dib7000p_config));
  2289. st->i2c_adap = i2c_adap;
  2290. st->i2c_addr = i2c_addr;
  2291. st->gpio_val = cfg->gpio_val;
  2292. st->gpio_dir = cfg->gpio_dir;
  2293. /* Ensure the output mode remains at the previous default if it's
  2294. * not specifically set by the caller.
  2295. */
  2296. if ((st->cfg.output_mode != OUTMODE_MPEG2_SERIAL) && (st->cfg.output_mode != OUTMODE_MPEG2_PAR_GATED_CLK))
  2297. st->cfg.output_mode = OUTMODE_MPEG2_FIFO;
  2298. demod = &st->demod;
  2299. demod->demodulator_priv = st;
  2300. memcpy(&st->demod.ops, &dib7000p_ops, sizeof(struct dvb_frontend_ops));
  2301. mutex_init(&st->i2c_buffer_lock);
  2302. dib7000p_write_word(st, 1287, 0x0003); /* sram lead in, rdy */
  2303. if (dib7000p_identify(st) != 0)
  2304. goto error;
  2305. st->version = dib7000p_read_word(st, 897);
  2306. /* FIXME: make sure the dev.parent field is initialized, or else
  2307. request_firmware() will hit an OOPS (this should be moved somewhere
  2308. more common) */
  2309. st->i2c_master.gated_tuner_i2c_adap.dev.parent = i2c_adap->dev.parent;
  2310. dibx000_init_i2c_master(&st->i2c_master, DIB7000P, st->i2c_adap, st->i2c_addr);
  2311. /* init 7090 tuner adapter */
  2312. strncpy(st->dib7090_tuner_adap.name, "DiB7090 tuner interface", sizeof(st->dib7090_tuner_adap.name));
  2313. st->dib7090_tuner_adap.algo = &dib7090_tuner_xfer_algo;
  2314. st->dib7090_tuner_adap.algo_data = NULL;
  2315. st->dib7090_tuner_adap.dev.parent = st->i2c_adap->dev.parent;
  2316. i2c_set_adapdata(&st->dib7090_tuner_adap, st);
  2317. i2c_add_adapter(&st->dib7090_tuner_adap);
  2318. dib7000p_demod_reset(st);
  2319. dib7000p_reset_stats(demod);
  2320. if (st->version == SOC7090) {
  2321. dib7090_set_output_mode(demod, st->cfg.output_mode);
  2322. dib7090_set_diversity_in(demod, 0);
  2323. }
  2324. return demod;
  2325. error:
  2326. kfree(st);
  2327. return NULL;
  2328. }
  2329. void *dib7000p_attach(struct dib7000p_ops *ops)
  2330. {
  2331. if (!ops)
  2332. return NULL;
  2333. ops->slave_reset = dib7090_slave_reset;
  2334. ops->get_adc_power = dib7090_get_adc_power;
  2335. ops->dib7000pc_detection = dib7000pc_detection;
  2336. ops->get_i2c_tuner = dib7090_get_i2c_tuner;
  2337. ops->tuner_sleep = dib7090_tuner_sleep;
  2338. ops->init = dib7000p_init;
  2339. ops->set_agc1_min = dib7000p_set_agc1_min;
  2340. ops->set_gpio = dib7000p_set_gpio;
  2341. ops->i2c_enumeration = dib7000p_i2c_enumeration;
  2342. ops->pid_filter = dib7000p_pid_filter;
  2343. ops->pid_filter_ctrl = dib7000p_pid_filter_ctrl;
  2344. ops->get_i2c_master = dib7000p_get_i2c_master;
  2345. ops->update_pll = dib7000p_update_pll;
  2346. ops->ctrl_timf = dib7000p_ctrl_timf;
  2347. ops->get_agc_values = dib7000p_get_agc_values;
  2348. ops->set_wbd_ref = dib7000p_set_wbd_ref;
  2349. return ops;
  2350. }
  2351. EXPORT_SYMBOL(dib7000p_attach);
  2352. static struct dvb_frontend_ops dib7000p_ops = {
  2353. .delsys = { SYS_DVBT },
  2354. .info = {
  2355. .name = "DiBcom 7000PC",
  2356. .frequency_min = 44250000,
  2357. .frequency_max = 867250000,
  2358. .frequency_stepsize = 62500,
  2359. .caps = FE_CAN_INVERSION_AUTO |
  2360. FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  2361. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  2362. FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
  2363. FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO | FE_CAN_RECOVER | FE_CAN_HIERARCHY_AUTO,
  2364. },
  2365. .release = dib7000p_release,
  2366. .init = dib7000p_wakeup,
  2367. .sleep = dib7000p_sleep,
  2368. .set_frontend = dib7000p_set_frontend,
  2369. .get_tune_settings = dib7000p_fe_get_tune_settings,
  2370. .get_frontend = dib7000p_get_frontend,
  2371. .read_status = dib7000p_read_status,
  2372. .read_ber = dib7000p_read_ber,
  2373. .read_signal_strength = dib7000p_read_signal_strength,
  2374. .read_snr = dib7000p_read_snr,
  2375. .read_ucblocks = dib7000p_read_unc_blocks,
  2376. };
  2377. MODULE_AUTHOR("Olivier Grenie <ogrenie@dibcom.fr>");
  2378. MODULE_AUTHOR("Patrick Boettcher <pboettcher@dibcom.fr>");
  2379. MODULE_DESCRIPTION("Driver for the DiBcom 7000PC COFDM demodulator");
  2380. MODULE_LICENSE("GPL");