dib7000p.c 74 KB

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