dib7000p.c 74 KB

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