stb0899_drv.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687
  1. /*
  2. STB0899 Multistandard Frontend driver
  3. Copyright (C) Manu Abraham (abraham.manu@gmail.com)
  4. Copyright (C) ST Microelectronics
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. #include <linux/init.h>
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/slab.h>
  21. #include <linux/string.h>
  22. #include <linux/dvb/frontend.h>
  23. #include "dvb_frontend.h"
  24. #include "stb0899_drv.h"
  25. #include "stb0899_priv.h"
  26. #include "stb0899_reg.h"
  27. static unsigned int verbose = 0;//1;
  28. module_param(verbose, int, 0644);
  29. /* C/N in dB/10, NIRM/NIRL */
  30. static const struct stb0899_tab stb0899_cn_tab[] = {
  31. { 200, 2600 },
  32. { 190, 2700 },
  33. { 180, 2860 },
  34. { 170, 3020 },
  35. { 160, 3210 },
  36. { 150, 3440 },
  37. { 140, 3710 },
  38. { 130, 4010 },
  39. { 120, 4360 },
  40. { 110, 4740 },
  41. { 100, 5190 },
  42. { 90, 5670 },
  43. { 80, 6200 },
  44. { 70, 6770 },
  45. { 60, 7360 },
  46. { 50, 7970 },
  47. { 40, 8250 },
  48. { 30, 9000 },
  49. { 20, 9450 },
  50. { 15, 9600 },
  51. };
  52. /* DVB-S AGCIQ_VALUE vs. signal level in dBm/10.
  53. * As measured, connected to a modulator.
  54. * -8.0 to -50.0 dBm directly connected,
  55. * -52.0 to -74.8 with extra attenuation.
  56. * Cut-off to AGCIQ_VALUE = 0x80 below -74.8dBm.
  57. * Crude linear extrapolation below -84.8dBm and above -8.0dBm.
  58. */
  59. static const struct stb0899_tab stb0899_dvbsrf_tab[] = {
  60. { -950, -128 },
  61. { -748, -94 },
  62. { -745, -92 },
  63. { -735, -90 },
  64. { -720, -87 },
  65. { -670, -77 },
  66. { -640, -70 },
  67. { -610, -62 },
  68. { -600, -60 },
  69. { -590, -56 },
  70. { -560, -41 },
  71. { -540, -25 },
  72. { -530, -17 },
  73. { -520, -11 },
  74. { -500, 1 },
  75. { -490, 6 },
  76. { -480, 10 },
  77. { -440, 22 },
  78. { -420, 27 },
  79. { -400, 31 },
  80. { -380, 34 },
  81. { -340, 40 },
  82. { -320, 43 },
  83. { -280, 48 },
  84. { -250, 52 },
  85. { -230, 55 },
  86. { -180, 61 },
  87. { -140, 66 },
  88. { -90, 73 },
  89. { -80, 74 },
  90. { 500, 127 }
  91. };
  92. /* DVB-S2 IF_AGC_GAIN vs. signal level in dBm/10.
  93. * As measured, connected to a modulator.
  94. * -8.0 to -50.1 dBm directly connected,
  95. * -53.0 to -76.6 with extra attenuation.
  96. * Cut-off to IF_AGC_GAIN = 0x3fff below -76.6dBm.
  97. * Crude linear extrapolation below -76.6dBm and above -8.0dBm.
  98. */
  99. static const struct stb0899_tab stb0899_dvbs2rf_tab[] = {
  100. { 700, 0 },
  101. { -80, 3217 },
  102. { -150, 3893 },
  103. { -190, 4217 },
  104. { -240, 4621 },
  105. { -280, 4945 },
  106. { -320, 5273 },
  107. { -350, 5545 },
  108. { -370, 5741 },
  109. { -410, 6147 },
  110. { -450, 6671 },
  111. { -490, 7413 },
  112. { -501, 7665 },
  113. { -530, 8767 },
  114. { -560, 10219 },
  115. { -580, 10939 },
  116. { -590, 11518 },
  117. { -600, 11723 },
  118. { -650, 12659 },
  119. { -690, 13219 },
  120. { -730, 13645 },
  121. { -750, 13909 },
  122. { -766, 14153 },
  123. { -999, 16383 }
  124. };
  125. /* DVB-S2 Es/N0 quant in dB/100 vs read value * 100*/
  126. static struct stb0899_tab stb0899_quant_tab[] = {
  127. { 0, 0 },
  128. { 0, 100 },
  129. { 600, 200 },
  130. { 950, 299 },
  131. { 1200, 398 },
  132. { 1400, 501 },
  133. { 1560, 603 },
  134. { 1690, 700 },
  135. { 1810, 804 },
  136. { 1910, 902 },
  137. { 2000, 1000 },
  138. { 2080, 1096 },
  139. { 2160, 1202 },
  140. { 2230, 1303 },
  141. { 2350, 1496 },
  142. { 2410, 1603 },
  143. { 2460, 1698 },
  144. { 2510, 1799 },
  145. { 2600, 1995 },
  146. { 2650, 2113 },
  147. { 2690, 2213 },
  148. { 2720, 2291 },
  149. { 2760, 2399 },
  150. { 2800, 2512 },
  151. { 2860, 2692 },
  152. { 2930, 2917 },
  153. { 2960, 3020 },
  154. { 3010, 3199 },
  155. { 3040, 3311 },
  156. { 3060, 3388 },
  157. { 3120, 3631 },
  158. { 3190, 3936 },
  159. { 3400, 5012 },
  160. { 3610, 6383 },
  161. { 3800, 7943 },
  162. { 4210, 12735 },
  163. { 4500, 17783 },
  164. { 4690, 22131 },
  165. { 4810, 25410 }
  166. };
  167. /* DVB-S2 Es/N0 estimate in dB/100 vs read value */
  168. static struct stb0899_tab stb0899_est_tab[] = {
  169. { 0, 0 },
  170. { 0, 1 },
  171. { 301, 2 },
  172. { 1204, 16 },
  173. { 1806, 64 },
  174. { 2408, 256 },
  175. { 2709, 512 },
  176. { 3010, 1023 },
  177. { 3311, 2046 },
  178. { 3612, 4093 },
  179. { 3823, 6653 },
  180. { 3913, 8185 },
  181. { 4010, 10233 },
  182. { 4107, 12794 },
  183. { 4214, 16368 },
  184. { 4266, 18450 },
  185. { 4311, 20464 },
  186. { 4353, 22542 },
  187. { 4391, 24604 },
  188. { 4425, 26607 },
  189. { 4457, 28642 },
  190. { 4487, 30690 },
  191. { 4515, 32734 },
  192. { 4612, 40926 },
  193. { 4692, 49204 },
  194. { 4816, 65464 },
  195. { 4913, 81846 },
  196. { 4993, 98401 },
  197. { 5060, 114815 },
  198. { 5118, 131220 },
  199. { 5200, 158489 },
  200. { 5300, 199526 },
  201. { 5400, 251189 },
  202. { 5500, 316228 },
  203. { 5600, 398107 },
  204. { 5720, 524807 },
  205. { 5721, 526017 },
  206. };
  207. static int _stb0899_read_reg(struct stb0899_state *state, unsigned int reg)
  208. {
  209. int ret;
  210. u8 b0[] = { reg >> 8, reg & 0xff };
  211. u8 buf;
  212. struct i2c_msg msg[] = {
  213. {
  214. .addr = state->config->demod_address,
  215. .flags = 0,
  216. .buf = b0,
  217. .len = 2
  218. },{
  219. .addr = state->config->demod_address,
  220. .flags = I2C_M_RD,
  221. .buf = &buf,
  222. .len = 1
  223. }
  224. };
  225. ret = i2c_transfer(state->i2c, msg, 2);
  226. if (ret != 2) {
  227. if (ret != -ERESTARTSYS)
  228. dprintk(state->verbose, FE_ERROR, 1,
  229. "Read error, Reg=[0x%02x], Status=%d",
  230. reg, ret);
  231. return ret < 0 ? ret : -EREMOTEIO;
  232. }
  233. if (unlikely(*state->verbose >= FE_DEBUGREG))
  234. dprintk(state->verbose, FE_ERROR, 1, "Reg=[0x%02x], data=%02x",
  235. reg, buf);
  236. return (unsigned int)buf;
  237. }
  238. int stb0899_read_reg(struct stb0899_state *state, unsigned int reg)
  239. {
  240. int result;
  241. result = _stb0899_read_reg(state, reg);
  242. /*
  243. * Bug ID 9:
  244. * access to 0xf2xx/0xf6xx
  245. * must be followed by read from 0xf2ff/0xf6ff.
  246. */
  247. if ((reg != 0xf2ff) && (reg != 0xf6ff) &&
  248. (((reg & 0xff00) == 0xf200) || ((reg & 0xff00) == 0xf600)))
  249. _stb0899_read_reg(state, (reg | 0x00ff));
  250. return result;
  251. }
  252. u32 _stb0899_read_s2reg(struct stb0899_state *state,
  253. u32 stb0899_i2cdev,
  254. u32 stb0899_base_addr,
  255. u16 stb0899_reg_offset)
  256. {
  257. int status;
  258. u32 data;
  259. u8 buf[7] = { 0 };
  260. u16 tmpaddr;
  261. u8 buf_0[] = {
  262. GETBYTE(stb0899_i2cdev, BYTE1), /* 0xf3 S2 Base Address (MSB) */
  263. GETBYTE(stb0899_i2cdev, BYTE0), /* 0xfc S2 Base Address (LSB) */
  264. GETBYTE(stb0899_base_addr, BYTE0), /* 0x00 Base Address (LSB) */
  265. GETBYTE(stb0899_base_addr, BYTE1), /* 0x04 Base Address (LSB) */
  266. GETBYTE(stb0899_base_addr, BYTE2), /* 0x00 Base Address (MSB) */
  267. GETBYTE(stb0899_base_addr, BYTE3), /* 0x00 Base Address (MSB) */
  268. };
  269. u8 buf_1[] = {
  270. 0x00, /* 0xf3 Reg Offset */
  271. 0x00, /* 0x44 Reg Offset */
  272. };
  273. struct i2c_msg msg_0 = {
  274. .addr = state->config->demod_address,
  275. .flags = 0,
  276. .buf = buf_0,
  277. .len = 6
  278. };
  279. struct i2c_msg msg_1 = {
  280. .addr = state->config->demod_address,
  281. .flags = 0,
  282. .buf = buf_1,
  283. .len = 2
  284. };
  285. struct i2c_msg msg_r = {
  286. .addr = state->config->demod_address,
  287. .flags = I2C_M_RD,
  288. .buf = buf,
  289. .len = 4
  290. };
  291. tmpaddr = stb0899_reg_offset & 0xff00;
  292. if (!(stb0899_reg_offset & 0x8))
  293. tmpaddr = stb0899_reg_offset | 0x20;
  294. buf_1[0] = GETBYTE(tmpaddr, BYTE1);
  295. buf_1[1] = GETBYTE(tmpaddr, BYTE0);
  296. status = i2c_transfer(state->i2c, &msg_0, 1);
  297. if (status < 1) {
  298. if (status != -ERESTARTSYS)
  299. printk(KERN_ERR "%s ERR(1), Device=[0x%04x], Base address=[0x%08x], Offset=[0x%04x], Status=%d\n",
  300. __func__, stb0899_i2cdev, stb0899_base_addr, stb0899_reg_offset, status);
  301. goto err;
  302. }
  303. /* Dummy */
  304. status = i2c_transfer(state->i2c, &msg_1, 1);
  305. if (status < 1)
  306. goto err;
  307. status = i2c_transfer(state->i2c, &msg_r, 1);
  308. if (status < 1)
  309. goto err;
  310. buf_1[0] = GETBYTE(stb0899_reg_offset, BYTE1);
  311. buf_1[1] = GETBYTE(stb0899_reg_offset, BYTE0);
  312. /* Actual */
  313. status = i2c_transfer(state->i2c, &msg_1, 1);
  314. if (status < 1) {
  315. if (status != -ERESTARTSYS)
  316. printk(KERN_ERR "%s ERR(2), Device=[0x%04x], Base address=[0x%08x], Offset=[0x%04x], Status=%d\n",
  317. __func__, stb0899_i2cdev, stb0899_base_addr, stb0899_reg_offset, status);
  318. goto err;
  319. }
  320. status = i2c_transfer(state->i2c, &msg_r, 1);
  321. if (status < 1) {
  322. if (status != -ERESTARTSYS)
  323. printk(KERN_ERR "%s ERR(3), Device=[0x%04x], Base address=[0x%08x], Offset=[0x%04x], Status=%d\n",
  324. __func__, stb0899_i2cdev, stb0899_base_addr, stb0899_reg_offset, status);
  325. return status < 0 ? status : -EREMOTEIO;
  326. }
  327. data = MAKEWORD32(buf[3], buf[2], buf[1], buf[0]);
  328. if (unlikely(*state->verbose >= FE_DEBUGREG))
  329. printk(KERN_DEBUG "%s Device=[0x%04x], Base address=[0x%08x], Offset=[0x%04x], Data=[0x%08x]\n",
  330. __func__, stb0899_i2cdev, stb0899_base_addr, stb0899_reg_offset, data);
  331. return data;
  332. err:
  333. return status < 0 ? status : -EREMOTEIO;
  334. }
  335. int stb0899_write_s2reg(struct stb0899_state *state,
  336. u32 stb0899_i2cdev,
  337. u32 stb0899_base_addr,
  338. u16 stb0899_reg_offset,
  339. u32 stb0899_data)
  340. {
  341. int status;
  342. /* Base Address Setup */
  343. u8 buf_0[] = {
  344. GETBYTE(stb0899_i2cdev, BYTE1), /* 0xf3 S2 Base Address (MSB) */
  345. GETBYTE(stb0899_i2cdev, BYTE0), /* 0xfc S2 Base Address (LSB) */
  346. GETBYTE(stb0899_base_addr, BYTE0), /* 0x00 Base Address (LSB) */
  347. GETBYTE(stb0899_base_addr, BYTE1), /* 0x04 Base Address (LSB) */
  348. GETBYTE(stb0899_base_addr, BYTE2), /* 0x00 Base Address (MSB) */
  349. GETBYTE(stb0899_base_addr, BYTE3), /* 0x00 Base Address (MSB) */
  350. };
  351. u8 buf_1[] = {
  352. 0x00, /* 0xf3 Reg Offset */
  353. 0x00, /* 0x44 Reg Offset */
  354. 0x00, /* data */
  355. 0x00, /* data */
  356. 0x00, /* data */
  357. 0x00, /* data */
  358. };
  359. struct i2c_msg msg_0 = {
  360. .addr = state->config->demod_address,
  361. .flags = 0,
  362. .buf = buf_0,
  363. .len = 6
  364. };
  365. struct i2c_msg msg_1 = {
  366. .addr = state->config->demod_address,
  367. .flags = 0,
  368. .buf = buf_1,
  369. .len = 6
  370. };
  371. buf_1[0] = GETBYTE(stb0899_reg_offset, BYTE1);
  372. buf_1[1] = GETBYTE(stb0899_reg_offset, BYTE0);
  373. buf_1[2] = GETBYTE(stb0899_data, BYTE0);
  374. buf_1[3] = GETBYTE(stb0899_data, BYTE1);
  375. buf_1[4] = GETBYTE(stb0899_data, BYTE2);
  376. buf_1[5] = GETBYTE(stb0899_data, BYTE3);
  377. if (unlikely(*state->verbose >= FE_DEBUGREG))
  378. printk(KERN_DEBUG "%s Device=[0x%04x], Base Address=[0x%08x], Offset=[0x%04x], Data=[0x%08x]\n",
  379. __func__, stb0899_i2cdev, stb0899_base_addr, stb0899_reg_offset, stb0899_data);
  380. status = i2c_transfer(state->i2c, &msg_0, 1);
  381. if (unlikely(status < 1)) {
  382. if (status != -ERESTARTSYS)
  383. printk(KERN_ERR "%s ERR (1), Device=[0x%04x], Base Address=[0x%08x], Offset=[0x%04x], Data=[0x%08x], status=%d\n",
  384. __func__, stb0899_i2cdev, stb0899_base_addr, stb0899_reg_offset, stb0899_data, status);
  385. goto err;
  386. }
  387. status = i2c_transfer(state->i2c, &msg_1, 1);
  388. if (unlikely(status < 1)) {
  389. if (status != -ERESTARTSYS)
  390. printk(KERN_ERR "%s ERR (2), Device=[0x%04x], Base Address=[0x%08x], Offset=[0x%04x], Data=[0x%08x], status=%d\n",
  391. __func__, stb0899_i2cdev, stb0899_base_addr, stb0899_reg_offset, stb0899_data, status);
  392. return status < 0 ? status : -EREMOTEIO;
  393. }
  394. return 0;
  395. err:
  396. return status < 0 ? status : -EREMOTEIO;
  397. }
  398. int stb0899_read_regs(struct stb0899_state *state, unsigned int reg, u8 *buf, u32 count)
  399. {
  400. int status;
  401. u8 b0[] = { reg >> 8, reg & 0xff };
  402. struct i2c_msg msg[] = {
  403. {
  404. .addr = state->config->demod_address,
  405. .flags = 0,
  406. .buf = b0,
  407. .len = 2
  408. },{
  409. .addr = state->config->demod_address,
  410. .flags = I2C_M_RD,
  411. .buf = buf,
  412. .len = count
  413. }
  414. };
  415. status = i2c_transfer(state->i2c, msg, 2);
  416. if (status != 2) {
  417. if (status != -ERESTARTSYS)
  418. printk(KERN_ERR "%s Read error, Reg=[0x%04x], Count=%u, Status=%d\n",
  419. __func__, reg, count, status);
  420. goto err;
  421. }
  422. /*
  423. * Bug ID 9:
  424. * access to 0xf2xx/0xf6xx
  425. * must be followed by read from 0xf2ff/0xf6ff.
  426. */
  427. if ((reg != 0xf2ff) && (reg != 0xf6ff) &&
  428. (((reg & 0xff00) == 0xf200) || ((reg & 0xff00) == 0xf600)))
  429. _stb0899_read_reg(state, (reg | 0x00ff));
  430. if (unlikely(*state->verbose >= FE_DEBUGREG)) {
  431. int i;
  432. printk(KERN_DEBUG "%s [0x%04x]:", __func__, reg);
  433. for (i = 0; i < count; i++) {
  434. printk(" %02x", buf[i]);
  435. }
  436. printk("\n");
  437. }
  438. return 0;
  439. err:
  440. return status < 0 ? status : -EREMOTEIO;
  441. }
  442. int stb0899_write_regs(struct stb0899_state *state, unsigned int reg, u8 *data, u32 count)
  443. {
  444. int ret;
  445. u8 buf[2 + count];
  446. struct i2c_msg i2c_msg = {
  447. .addr = state->config->demod_address,
  448. .flags = 0,
  449. .buf = buf,
  450. .len = 2 + count
  451. };
  452. buf[0] = reg >> 8;
  453. buf[1] = reg & 0xff;
  454. memcpy(&buf[2], data, count);
  455. if (unlikely(*state->verbose >= FE_DEBUGREG)) {
  456. int i;
  457. printk(KERN_DEBUG "%s [0x%04x]:", __func__, reg);
  458. for (i = 0; i < count; i++)
  459. printk(" %02x", data[i]);
  460. printk("\n");
  461. }
  462. ret = i2c_transfer(state->i2c, &i2c_msg, 1);
  463. /*
  464. * Bug ID 9:
  465. * access to 0xf2xx/0xf6xx
  466. * must be followed by read from 0xf2ff/0xf6ff.
  467. */
  468. if ((((reg & 0xff00) == 0xf200) || ((reg & 0xff00) == 0xf600)))
  469. stb0899_read_reg(state, (reg | 0x00ff));
  470. if (ret != 1) {
  471. if (ret != -ERESTARTSYS)
  472. dprintk(state->verbose, FE_ERROR, 1, "Reg=[0x%04x], Data=[0x%02x ...], Count=%u, Status=%d",
  473. reg, data[0], count, ret);
  474. return ret < 0 ? ret : -EREMOTEIO;
  475. }
  476. return 0;
  477. }
  478. int stb0899_write_reg(struct stb0899_state *state, unsigned int reg, u8 data)
  479. {
  480. return stb0899_write_regs(state, reg, &data, 1);
  481. }
  482. /*
  483. * stb0899_get_mclk
  484. * Get STB0899 master clock frequency
  485. * ExtClk: external clock frequency (Hz)
  486. */
  487. static u32 stb0899_get_mclk(struct stb0899_state *state)
  488. {
  489. u32 mclk = 0, div = 0;
  490. div = stb0899_read_reg(state, STB0899_NCOARSE);
  491. mclk = (div + 1) * state->config->xtal_freq / 6;
  492. dprintk(state->verbose, FE_DEBUG, 1, "div=%d, mclk=%d", div, mclk);
  493. return mclk;
  494. }
  495. /*
  496. * stb0899_set_mclk
  497. * Set STB0899 master Clock frequency
  498. * Mclk: demodulator master clock
  499. * ExtClk: external clock frequency (Hz)
  500. */
  501. static void stb0899_set_mclk(struct stb0899_state *state, u32 Mclk)
  502. {
  503. struct stb0899_internal *internal = &state->internal;
  504. u8 mdiv = 0;
  505. dprintk(state->verbose, FE_DEBUG, 1, "state->config=%p", state->config);
  506. mdiv = ((6 * Mclk) / state->config->xtal_freq) - 1;
  507. dprintk(state->verbose, FE_DEBUG, 1, "mdiv=%d", mdiv);
  508. stb0899_write_reg(state, STB0899_NCOARSE, mdiv);
  509. internal->master_clk = stb0899_get_mclk(state);
  510. dprintk(state->verbose, FE_DEBUG, 1, "MasterCLOCK=%d", internal->master_clk);
  511. }
  512. static int stb0899_postproc(struct stb0899_state *state, u8 ctl, int enable)
  513. {
  514. struct stb0899_config *config = state->config;
  515. const struct stb0899_postproc *postproc = config->postproc;
  516. /* post process event */
  517. if (postproc) {
  518. if (enable) {
  519. if (postproc[ctl].level == STB0899_GPIOPULLUP)
  520. stb0899_write_reg(state, postproc[ctl].gpio, 0x02);
  521. else
  522. stb0899_write_reg(state, postproc[ctl].gpio, 0x82);
  523. } else {
  524. if (postproc[ctl].level == STB0899_GPIOPULLUP)
  525. stb0899_write_reg(state, postproc[ctl].gpio, 0x82);
  526. else
  527. stb0899_write_reg(state, postproc[ctl].gpio, 0x02);
  528. }
  529. }
  530. return 0;
  531. }
  532. static void stb0899_release(struct dvb_frontend *fe)
  533. {
  534. struct stb0899_state *state = fe->demodulator_priv;
  535. dprintk(state->verbose, FE_DEBUG, 1, "Release Frontend");
  536. /* post process event */
  537. stb0899_postproc(state, STB0899_POSTPROC_GPIO_POWER, 0);
  538. kfree(state);
  539. }
  540. /*
  541. * stb0899_get_alpha
  542. * return: rolloff
  543. */
  544. static int stb0899_get_alpha(struct stb0899_state *state)
  545. {
  546. u8 mode_coeff;
  547. mode_coeff = stb0899_read_reg(state, STB0899_DEMOD);
  548. if (STB0899_GETFIELD(MODECOEFF, mode_coeff) == 1)
  549. return 20;
  550. else
  551. return 35;
  552. }
  553. /*
  554. * stb0899_init_calc
  555. */
  556. static void stb0899_init_calc(struct stb0899_state *state)
  557. {
  558. struct stb0899_internal *internal = &state->internal;
  559. int master_clk;
  560. u8 agc[2];
  561. u8 agc1cn;
  562. u32 reg;
  563. /* Read registers (in burst mode) */
  564. agc1cn = stb0899_read_reg(state, STB0899_AGC1CN);
  565. stb0899_read_regs(state, STB0899_AGC1REF, agc, 2); /* AGC1R and AGC2O */
  566. /* Initial calculations */
  567. master_clk = stb0899_get_mclk(state);
  568. internal->t_agc1 = 0;
  569. internal->t_agc2 = 0;
  570. internal->master_clk = master_clk;
  571. internal->mclk = master_clk / 65536L;
  572. internal->rolloff = stb0899_get_alpha(state);
  573. /* DVBS2 Initial calculations */
  574. /* Set AGC value to the middle */
  575. internal->agc_gain = 8154;
  576. reg = STB0899_READ_S2REG(STB0899_S2DEMOD, IF_AGC_CNTRL);
  577. STB0899_SETFIELD_VAL(IF_GAIN_INIT, reg, internal->agc_gain);
  578. stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_IF_AGC_CNTRL, STB0899_OFF0_IF_AGC_CNTRL, reg);
  579. reg = STB0899_READ_S2REG(STB0899_S2DEMOD, RRC_ALPHA);
  580. internal->rrc_alpha = STB0899_GETFIELD(RRC_ALPHA, reg);
  581. internal->center_freq = 0;
  582. internal->av_frame_coarse = 10;
  583. internal->av_frame_fine = 20;
  584. internal->step_size = 2;
  585. /*
  586. if ((pParams->SpectralInv == FE_IQ_NORMAL) || (pParams->SpectralInv == FE_IQ_AUTO))
  587. pParams->IQLocked = 0;
  588. else
  589. pParams->IQLocked = 1;
  590. */
  591. }
  592. static int stb0899_wait_diseqc_fifo_empty(struct stb0899_state *state, int timeout)
  593. {
  594. u8 reg = 0;
  595. unsigned long start = jiffies;
  596. while (1) {
  597. reg = stb0899_read_reg(state, STB0899_DISSTATUS);
  598. if (!STB0899_GETFIELD(FIFOFULL, reg))
  599. break;
  600. if ((jiffies - start) > timeout) {
  601. dprintk(state->verbose, FE_ERROR, 1, "timed out !!");
  602. return -ETIMEDOUT;
  603. }
  604. }
  605. return 0;
  606. }
  607. static int stb0899_send_diseqc_msg(struct dvb_frontend *fe, struct dvb_diseqc_master_cmd *cmd)
  608. {
  609. struct stb0899_state *state = fe->demodulator_priv;
  610. u8 reg, i;
  611. if (cmd->msg_len > 8)
  612. return -EINVAL;
  613. /* enable FIFO precharge */
  614. reg = stb0899_read_reg(state, STB0899_DISCNTRL1);
  615. STB0899_SETFIELD_VAL(DISPRECHARGE, reg, 1);
  616. stb0899_write_reg(state, STB0899_DISCNTRL1, reg);
  617. for (i = 0; i < cmd->msg_len; i++) {
  618. /* wait for FIFO empty */
  619. if (stb0899_wait_diseqc_fifo_empty(state, 10) < 0)
  620. return -ETIMEDOUT;
  621. stb0899_write_reg(state, STB0899_DISFIFO, cmd->msg[i]);
  622. }
  623. reg = stb0899_read_reg(state, STB0899_DISCNTRL1);
  624. STB0899_SETFIELD_VAL(DISPRECHARGE, reg, 0);
  625. stb0899_write_reg(state, STB0899_DISCNTRL1, reg);
  626. msleep(100);
  627. return 0;
  628. }
  629. static int stb0899_wait_diseqc_rxidle(struct stb0899_state *state, int timeout)
  630. {
  631. u8 reg = 0;
  632. unsigned long start = jiffies;
  633. while (!STB0899_GETFIELD(RXEND, reg)) {
  634. reg = stb0899_read_reg(state, STB0899_DISRX_ST0);
  635. if (jiffies - start > timeout) {
  636. dprintk(state->verbose, FE_ERROR, 1, "timed out!!");
  637. return -ETIMEDOUT;
  638. }
  639. msleep(10);
  640. }
  641. return 0;
  642. }
  643. static int stb0899_recv_slave_reply(struct dvb_frontend *fe, struct dvb_diseqc_slave_reply *reply)
  644. {
  645. struct stb0899_state *state = fe->demodulator_priv;
  646. u8 reg, length = 0, i;
  647. int result;
  648. if (stb0899_wait_diseqc_rxidle(state, 100) < 0)
  649. return -ETIMEDOUT;
  650. reg = stb0899_read_reg(state, STB0899_DISRX_ST0);
  651. if (STB0899_GETFIELD(RXEND, reg)) {
  652. reg = stb0899_read_reg(state, STB0899_DISRX_ST1);
  653. length = STB0899_GETFIELD(FIFOBYTENBR, reg);
  654. if (length > sizeof (reply->msg)) {
  655. result = -EOVERFLOW;
  656. goto exit;
  657. }
  658. reply->msg_len = length;
  659. /* extract data */
  660. for (i = 0; i < length; i++)
  661. reply->msg[i] = stb0899_read_reg(state, STB0899_DISFIFO);
  662. }
  663. return 0;
  664. exit:
  665. return result;
  666. }
  667. static int stb0899_wait_diseqc_txidle(struct stb0899_state *state, int timeout)
  668. {
  669. u8 reg = 0;
  670. unsigned long start = jiffies;
  671. while (!STB0899_GETFIELD(TXIDLE, reg)) {
  672. reg = stb0899_read_reg(state, STB0899_DISSTATUS);
  673. if (jiffies - start > timeout) {
  674. dprintk(state->verbose, FE_ERROR, 1, "timed out!!");
  675. return -ETIMEDOUT;
  676. }
  677. msleep(10);
  678. }
  679. return 0;
  680. }
  681. static int stb0899_send_diseqc_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t burst)
  682. {
  683. struct stb0899_state *state = fe->demodulator_priv;
  684. u8 reg, old_state;
  685. /* wait for diseqc idle */
  686. if (stb0899_wait_diseqc_txidle(state, 100) < 0)
  687. return -ETIMEDOUT;
  688. reg = stb0899_read_reg(state, STB0899_DISCNTRL1);
  689. old_state = reg;
  690. /* set to burst mode */
  691. STB0899_SETFIELD_VAL(DISEQCMODE, reg, 0x03);
  692. STB0899_SETFIELD_VAL(DISPRECHARGE, reg, 0x01);
  693. stb0899_write_reg(state, STB0899_DISCNTRL1, reg);
  694. switch (burst) {
  695. case SEC_MINI_A:
  696. /* unmodulated */
  697. stb0899_write_reg(state, STB0899_DISFIFO, 0x00);
  698. break;
  699. case SEC_MINI_B:
  700. /* modulated */
  701. stb0899_write_reg(state, STB0899_DISFIFO, 0xff);
  702. break;
  703. }
  704. reg = stb0899_read_reg(state, STB0899_DISCNTRL1);
  705. STB0899_SETFIELD_VAL(DISPRECHARGE, reg, 0x00);
  706. stb0899_write_reg(state, STB0899_DISCNTRL1, reg);
  707. /* wait for diseqc idle */
  708. if (stb0899_wait_diseqc_txidle(state, 100) < 0)
  709. return -ETIMEDOUT;
  710. /* restore state */
  711. stb0899_write_reg(state, STB0899_DISCNTRL1, old_state);
  712. return 0;
  713. }
  714. static int stb0899_diseqc_init(struct stb0899_state *state)
  715. {
  716. struct dvb_diseqc_master_cmd tx_data;
  717. /*
  718. struct dvb_diseqc_slave_reply rx_data;
  719. */
  720. u8 f22_tx, f22_rx, reg;
  721. u32 mclk, tx_freq = 22000;/* count = 0, i; */
  722. tx_data.msg[0] = 0xe2;
  723. tx_data.msg_len = 3;
  724. reg = stb0899_read_reg(state, STB0899_DISCNTRL2);
  725. STB0899_SETFIELD_VAL(ONECHIP_TRX, reg, 0);
  726. stb0899_write_reg(state, STB0899_DISCNTRL2, reg);
  727. /* disable Tx spy */
  728. reg = stb0899_read_reg(state, STB0899_DISCNTRL1);
  729. STB0899_SETFIELD_VAL(DISEQCRESET, reg, 1);
  730. stb0899_write_reg(state, STB0899_DISCNTRL1, reg);
  731. reg = stb0899_read_reg(state, STB0899_DISCNTRL1);
  732. STB0899_SETFIELD_VAL(DISEQCRESET, reg, 0);
  733. stb0899_write_reg(state, STB0899_DISCNTRL1, reg);
  734. mclk = stb0899_get_mclk(state);
  735. f22_tx = mclk / (tx_freq * 32);
  736. stb0899_write_reg(state, STB0899_DISF22, f22_tx); /* DiSEqC Tx freq */
  737. state->rx_freq = 20000;
  738. f22_rx = mclk / (state->rx_freq * 32);
  739. return 0;
  740. }
  741. static int stb0899_sleep(struct dvb_frontend *fe)
  742. {
  743. struct stb0899_state *state = fe->demodulator_priv;
  744. /*
  745. u8 reg;
  746. */
  747. dprintk(state->verbose, FE_DEBUG, 1, "Going to Sleep .. (Really tired .. :-))");
  748. /* post process event */
  749. stb0899_postproc(state, STB0899_POSTPROC_GPIO_POWER, 0);
  750. return 0;
  751. }
  752. static int stb0899_wakeup(struct dvb_frontend *fe)
  753. {
  754. int rc;
  755. struct stb0899_state *state = fe->demodulator_priv;
  756. if ((rc = stb0899_write_reg(state, STB0899_SYNTCTRL, STB0899_SELOSCI)))
  757. return rc;
  758. /* Activate all clocks; DVB-S2 registers are inaccessible otherwise. */
  759. if ((rc = stb0899_write_reg(state, STB0899_STOPCLK1, 0x00)))
  760. return rc;
  761. if ((rc = stb0899_write_reg(state, STB0899_STOPCLK2, 0x00)))
  762. return rc;
  763. /* post process event */
  764. stb0899_postproc(state, STB0899_POSTPROC_GPIO_POWER, 1);
  765. return 0;
  766. }
  767. static int stb0899_init(struct dvb_frontend *fe)
  768. {
  769. int i;
  770. struct stb0899_state *state = fe->demodulator_priv;
  771. struct stb0899_config *config = state->config;
  772. dprintk(state->verbose, FE_DEBUG, 1, "Initializing STB0899 ... ");
  773. /* init device */
  774. dprintk(state->verbose, FE_DEBUG, 1, "init device");
  775. for (i = 0; config->init_dev[i].address != 0xffff; i++)
  776. stb0899_write_reg(state, config->init_dev[i].address, config->init_dev[i].data);
  777. dprintk(state->verbose, FE_DEBUG, 1, "init S2 demod");
  778. /* init S2 demod */
  779. for (i = 0; config->init_s2_demod[i].offset != 0xffff; i++)
  780. stb0899_write_s2reg(state, STB0899_S2DEMOD,
  781. config->init_s2_demod[i].base_address,
  782. config->init_s2_demod[i].offset,
  783. config->init_s2_demod[i].data);
  784. dprintk(state->verbose, FE_DEBUG, 1, "init S1 demod");
  785. /* init S1 demod */
  786. for (i = 0; config->init_s1_demod[i].address != 0xffff; i++)
  787. stb0899_write_reg(state, config->init_s1_demod[i].address, config->init_s1_demod[i].data);
  788. dprintk(state->verbose, FE_DEBUG, 1, "init S2 FEC");
  789. /* init S2 fec */
  790. for (i = 0; config->init_s2_fec[i].offset != 0xffff; i++)
  791. stb0899_write_s2reg(state, STB0899_S2FEC,
  792. config->init_s2_fec[i].base_address,
  793. config->init_s2_fec[i].offset,
  794. config->init_s2_fec[i].data);
  795. dprintk(state->verbose, FE_DEBUG, 1, "init TST");
  796. /* init test */
  797. for (i = 0; config->init_tst[i].address != 0xffff; i++)
  798. stb0899_write_reg(state, config->init_tst[i].address, config->init_tst[i].data);
  799. stb0899_init_calc(state);
  800. stb0899_diseqc_init(state);
  801. return 0;
  802. }
  803. static int stb0899_table_lookup(const struct stb0899_tab *tab, int max, int val)
  804. {
  805. int res = 0;
  806. int min = 0, med;
  807. if (val < tab[min].read)
  808. res = tab[min].real;
  809. else if (val >= tab[max].read)
  810. res = tab[max].real;
  811. else {
  812. while ((max - min) > 1) {
  813. med = (max + min) / 2;
  814. if (val >= tab[min].read && val < tab[med].read)
  815. max = med;
  816. else
  817. min = med;
  818. }
  819. res = ((val - tab[min].read) *
  820. (tab[max].real - tab[min].real) /
  821. (tab[max].read - tab[min].read)) +
  822. tab[min].real;
  823. }
  824. return res;
  825. }
  826. static int stb0899_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
  827. {
  828. struct stb0899_state *state = fe->demodulator_priv;
  829. struct stb0899_internal *internal = &state->internal;
  830. int val;
  831. u32 reg;
  832. switch (state->delsys) {
  833. case SYS_DVBS:
  834. case SYS_DSS:
  835. if (internal->lock) {
  836. reg = stb0899_read_reg(state, STB0899_VSTATUS);
  837. if (STB0899_GETFIELD(VSTATUS_LOCKEDVIT, reg)) {
  838. reg = stb0899_read_reg(state, STB0899_AGCIQIN);
  839. val = (s32)(s8)STB0899_GETFIELD(AGCIQVALUE, reg);
  840. *strength = stb0899_table_lookup(stb0899_dvbsrf_tab, ARRAY_SIZE(stb0899_dvbsrf_tab) - 1, val);
  841. *strength += 750;
  842. dprintk(state->verbose, FE_DEBUG, 1, "AGCIQVALUE = 0x%02x, C = %d * 0.1 dBm",
  843. val & 0xff, *strength);
  844. }
  845. }
  846. break;
  847. case SYS_DVBS2:
  848. if (internal->lock) {
  849. reg = STB0899_READ_S2REG(STB0899_DEMOD, IF_AGC_GAIN);
  850. val = STB0899_GETFIELD(IF_AGC_GAIN, reg);
  851. *strength = stb0899_table_lookup(stb0899_dvbs2rf_tab, ARRAY_SIZE(stb0899_dvbs2rf_tab) - 1, val);
  852. *strength += 750;
  853. dprintk(state->verbose, FE_DEBUG, 1, "IF_AGC_GAIN = 0x%04x, C = %d * 0.1 dBm",
  854. val & 0x3fff, *strength);
  855. }
  856. break;
  857. default:
  858. dprintk(state->verbose, FE_DEBUG, 1, "Unsupported delivery system");
  859. return -EINVAL;
  860. }
  861. return 0;
  862. }
  863. static int stb0899_read_snr(struct dvb_frontend *fe, u16 *snr)
  864. {
  865. struct stb0899_state *state = fe->demodulator_priv;
  866. struct stb0899_internal *internal = &state->internal;
  867. unsigned int val, quant, quantn = -1, est, estn = -1;
  868. u8 buf[2];
  869. u32 reg;
  870. reg = stb0899_read_reg(state, STB0899_VSTATUS);
  871. switch (state->delsys) {
  872. case SYS_DVBS:
  873. case SYS_DSS:
  874. if (internal->lock) {
  875. if (STB0899_GETFIELD(VSTATUS_LOCKEDVIT, reg)) {
  876. stb0899_read_regs(state, STB0899_NIRM, buf, 2);
  877. val = MAKEWORD16(buf[0], buf[1]);
  878. *snr = stb0899_table_lookup(stb0899_cn_tab, ARRAY_SIZE(stb0899_cn_tab) - 1, val);
  879. dprintk(state->verbose, FE_DEBUG, 1, "NIR = 0x%02x%02x = %u, C/N = %d * 0.1 dBm\n",
  880. buf[0], buf[1], val, *snr);
  881. }
  882. }
  883. break;
  884. case SYS_DVBS2:
  885. if (internal->lock) {
  886. reg = STB0899_READ_S2REG(STB0899_S2DEMOD, UWP_CNTRL1);
  887. quant = STB0899_GETFIELD(UWP_ESN0_QUANT, reg);
  888. reg = STB0899_READ_S2REG(STB0899_S2DEMOD, UWP_STAT2);
  889. est = STB0899_GETFIELD(ESN0_EST, reg);
  890. if (est == 1)
  891. val = 301; /* C/N = 30.1 dB */
  892. else if (est == 2)
  893. val = 270; /* C/N = 27.0 dB */
  894. else {
  895. /* quantn = 100 * log(quant^2) */
  896. quantn = stb0899_table_lookup(stb0899_quant_tab, ARRAY_SIZE(stb0899_quant_tab) - 1, quant * 100);
  897. /* estn = 100 * log(est) */
  898. estn = stb0899_table_lookup(stb0899_est_tab, ARRAY_SIZE(stb0899_est_tab) - 1, est);
  899. /* snr(dBm/10) = -10*(log(est)-log(quant^2)) => snr(dBm/10) = (100*log(quant^2)-100*log(est))/10 */
  900. val = (quantn - estn) / 10;
  901. }
  902. *snr = val;
  903. dprintk(state->verbose, FE_DEBUG, 1, "Es/N0 quant = %d (%d) estimate = %u (%d), C/N = %d * 0.1 dBm",
  904. quant, quantn, est, estn, val);
  905. }
  906. break;
  907. default:
  908. dprintk(state->verbose, FE_DEBUG, 1, "Unsupported delivery system");
  909. return -EINVAL;
  910. }
  911. return 0;
  912. }
  913. static int stb0899_read_status(struct dvb_frontend *fe, enum fe_status *status)
  914. {
  915. struct stb0899_state *state = fe->demodulator_priv;
  916. struct stb0899_internal *internal = &state->internal;
  917. u8 reg;
  918. *status = 0;
  919. switch (state->delsys) {
  920. case SYS_DVBS:
  921. case SYS_DSS:
  922. dprintk(state->verbose, FE_DEBUG, 1, "Delivery system DVB-S/DSS");
  923. if (internal->lock) {
  924. reg = stb0899_read_reg(state, STB0899_VSTATUS);
  925. if (STB0899_GETFIELD(VSTATUS_LOCKEDVIT, reg)) {
  926. dprintk(state->verbose, FE_DEBUG, 1, "--------> FE_HAS_CARRIER | FE_HAS_LOCK");
  927. *status |= FE_HAS_CARRIER | FE_HAS_LOCK;
  928. reg = stb0899_read_reg(state, STB0899_PLPARM);
  929. if (STB0899_GETFIELD(VITCURPUN, reg)) {
  930. dprintk(state->verbose, FE_DEBUG, 1, "--------> FE_HAS_VITERBI | FE_HAS_SYNC");
  931. *status |= FE_HAS_VITERBI | FE_HAS_SYNC;
  932. /* post process event */
  933. stb0899_postproc(state, STB0899_POSTPROC_GPIO_LOCK, 1);
  934. }
  935. }
  936. }
  937. break;
  938. case SYS_DVBS2:
  939. dprintk(state->verbose, FE_DEBUG, 1, "Delivery system DVB-S2");
  940. if (internal->lock) {
  941. reg = STB0899_READ_S2REG(STB0899_S2DEMOD, DMD_STAT2);
  942. if (STB0899_GETFIELD(UWP_LOCK, reg) && STB0899_GETFIELD(CSM_LOCK, reg)) {
  943. *status |= FE_HAS_CARRIER;
  944. dprintk(state->verbose, FE_DEBUG, 1,
  945. "UWP & CSM Lock ! ---> DVB-S2 FE_HAS_CARRIER");
  946. reg = stb0899_read_reg(state, STB0899_CFGPDELSTATUS1);
  947. if (STB0899_GETFIELD(CFGPDELSTATUS_LOCK, reg)) {
  948. *status |= FE_HAS_LOCK;
  949. dprintk(state->verbose, FE_DEBUG, 1,
  950. "Packet Delineator Locked ! -----> DVB-S2 FE_HAS_LOCK");
  951. }
  952. if (STB0899_GETFIELD(CONTINUOUS_STREAM, reg)) {
  953. *status |= FE_HAS_VITERBI;
  954. dprintk(state->verbose, FE_DEBUG, 1,
  955. "Packet Delineator found VITERBI ! -----> DVB-S2 FE_HAS_VITERBI");
  956. }
  957. if (STB0899_GETFIELD(ACCEPTED_STREAM, reg)) {
  958. *status |= FE_HAS_SYNC;
  959. dprintk(state->verbose, FE_DEBUG, 1,
  960. "Packet Delineator found SYNC ! -----> DVB-S2 FE_HAS_SYNC");
  961. /* post process event */
  962. stb0899_postproc(state, STB0899_POSTPROC_GPIO_LOCK, 1);
  963. }
  964. }
  965. }
  966. break;
  967. default:
  968. dprintk(state->verbose, FE_DEBUG, 1, "Unsupported delivery system");
  969. return -EINVAL;
  970. }
  971. return 0;
  972. }
  973. /*
  974. * stb0899_get_error
  975. * viterbi error for DVB-S/DSS
  976. * packet error for DVB-S2
  977. * Bit Error Rate or Packet Error Rate * 10 ^ 7
  978. */
  979. static int stb0899_read_ber(struct dvb_frontend *fe, u32 *ber)
  980. {
  981. struct stb0899_state *state = fe->demodulator_priv;
  982. struct stb0899_internal *internal = &state->internal;
  983. u8 lsb, msb;
  984. u32 i;
  985. *ber = 0;
  986. switch (state->delsys) {
  987. case SYS_DVBS:
  988. case SYS_DSS:
  989. if (internal->lock) {
  990. /* average 5 BER values */
  991. for (i = 0; i < 5; i++) {
  992. msleep(100);
  993. lsb = stb0899_read_reg(state, STB0899_ECNT1L);
  994. msb = stb0899_read_reg(state, STB0899_ECNT1M);
  995. *ber += MAKEWORD16(msb, lsb);
  996. }
  997. *ber /= 5;
  998. /* Viterbi Check */
  999. if (STB0899_GETFIELD(VSTATUS_PRFVIT, internal->v_status)) {
  1000. /* Error Rate */
  1001. *ber *= 9766;
  1002. /* ber = ber * 10 ^ 7 */
  1003. *ber /= (-1 + (1 << (2 * STB0899_GETFIELD(NOE, internal->err_ctrl))));
  1004. *ber /= 8;
  1005. }
  1006. }
  1007. break;
  1008. case SYS_DVBS2:
  1009. if (internal->lock) {
  1010. /* Average 5 PER values */
  1011. for (i = 0; i < 5; i++) {
  1012. msleep(100);
  1013. lsb = stb0899_read_reg(state, STB0899_ECNT1L);
  1014. msb = stb0899_read_reg(state, STB0899_ECNT1M);
  1015. *ber += MAKEWORD16(msb, lsb);
  1016. }
  1017. /* ber = ber * 10 ^ 7 */
  1018. *ber *= 10000000;
  1019. *ber /= (-1 + (1 << (4 + 2 * STB0899_GETFIELD(NOE, internal->err_ctrl))));
  1020. }
  1021. break;
  1022. default:
  1023. dprintk(state->verbose, FE_DEBUG, 1, "Unsupported delivery system");
  1024. return -EINVAL;
  1025. }
  1026. return 0;
  1027. }
  1028. static int stb0899_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
  1029. {
  1030. struct stb0899_state *state = fe->demodulator_priv;
  1031. switch (voltage) {
  1032. case SEC_VOLTAGE_13:
  1033. stb0899_write_reg(state, STB0899_GPIO00CFG, 0x82);
  1034. stb0899_write_reg(state, STB0899_GPIO01CFG, 0x02);
  1035. stb0899_write_reg(state, STB0899_GPIO02CFG, 0x00);
  1036. break;
  1037. case SEC_VOLTAGE_18:
  1038. stb0899_write_reg(state, STB0899_GPIO00CFG, 0x02);
  1039. stb0899_write_reg(state, STB0899_GPIO01CFG, 0x02);
  1040. stb0899_write_reg(state, STB0899_GPIO02CFG, 0x82);
  1041. break;
  1042. case SEC_VOLTAGE_OFF:
  1043. stb0899_write_reg(state, STB0899_GPIO00CFG, 0x82);
  1044. stb0899_write_reg(state, STB0899_GPIO01CFG, 0x82);
  1045. stb0899_write_reg(state, STB0899_GPIO02CFG, 0x82);
  1046. break;
  1047. default:
  1048. return -EINVAL;
  1049. }
  1050. return 0;
  1051. }
  1052. static int stb0899_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
  1053. {
  1054. struct stb0899_state *state = fe->demodulator_priv;
  1055. struct stb0899_internal *internal = &state->internal;
  1056. u8 div, reg;
  1057. /* wait for diseqc idle */
  1058. if (stb0899_wait_diseqc_txidle(state, 100) < 0)
  1059. return -ETIMEDOUT;
  1060. switch (tone) {
  1061. case SEC_TONE_ON:
  1062. div = (internal->master_clk / 100) / 5632;
  1063. div = (div + 5) / 10;
  1064. stb0899_write_reg(state, STB0899_DISEQCOCFG, 0x66);
  1065. reg = stb0899_read_reg(state, STB0899_ACRPRESC);
  1066. STB0899_SETFIELD_VAL(ACRPRESC, reg, 0x03);
  1067. stb0899_write_reg(state, STB0899_ACRPRESC, reg);
  1068. stb0899_write_reg(state, STB0899_ACRDIV1, div);
  1069. break;
  1070. case SEC_TONE_OFF:
  1071. stb0899_write_reg(state, STB0899_DISEQCOCFG, 0x20);
  1072. break;
  1073. default:
  1074. return -EINVAL;
  1075. }
  1076. return 0;
  1077. }
  1078. int stb0899_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
  1079. {
  1080. int i2c_stat;
  1081. struct stb0899_state *state = fe->demodulator_priv;
  1082. i2c_stat = stb0899_read_reg(state, STB0899_I2CRPT);
  1083. if (i2c_stat < 0)
  1084. goto err;
  1085. if (enable) {
  1086. dprintk(state->verbose, FE_DEBUG, 1, "Enabling I2C Repeater ...");
  1087. i2c_stat |= STB0899_I2CTON;
  1088. if (stb0899_write_reg(state, STB0899_I2CRPT, i2c_stat) < 0)
  1089. goto err;
  1090. } else {
  1091. dprintk(state->verbose, FE_DEBUG, 1, "Disabling I2C Repeater ...");
  1092. i2c_stat &= ~STB0899_I2CTON;
  1093. if (stb0899_write_reg(state, STB0899_I2CRPT, i2c_stat) < 0)
  1094. goto err;
  1095. }
  1096. return 0;
  1097. err:
  1098. dprintk(state->verbose, FE_ERROR, 1, "I2C Repeater control failed");
  1099. return -EREMOTEIO;
  1100. }
  1101. static inline void CONVERT32(u32 x, char *str)
  1102. {
  1103. *str++ = (x >> 24) & 0xff;
  1104. *str++ = (x >> 16) & 0xff;
  1105. *str++ = (x >> 8) & 0xff;
  1106. *str++ = (x >> 0) & 0xff;
  1107. *str = '\0';
  1108. }
  1109. int stb0899_get_dev_id(struct stb0899_state *state)
  1110. {
  1111. u8 chip_id, release;
  1112. u16 id;
  1113. u32 demod_ver = 0, fec_ver = 0;
  1114. char demod_str[5] = { 0 };
  1115. char fec_str[5] = { 0 };
  1116. id = stb0899_read_reg(state, STB0899_DEV_ID);
  1117. dprintk(state->verbose, FE_DEBUG, 1, "ID reg=[0x%02x]", id);
  1118. chip_id = STB0899_GETFIELD(CHIP_ID, id);
  1119. release = STB0899_GETFIELD(CHIP_REL, id);
  1120. dprintk(state->verbose, FE_ERROR, 1, "Device ID=[%d], Release=[%d]",
  1121. chip_id, release);
  1122. CONVERT32(STB0899_READ_S2REG(STB0899_S2DEMOD, DMD_CORE_ID), (char *)&demod_str);
  1123. demod_ver = STB0899_READ_S2REG(STB0899_S2DEMOD, DMD_VERSION_ID);
  1124. dprintk(state->verbose, FE_ERROR, 1, "Demodulator Core ID=[%s], Version=[%d]", (char *) &demod_str, demod_ver);
  1125. CONVERT32(STB0899_READ_S2REG(STB0899_S2FEC, FEC_CORE_ID_REG), (char *)&fec_str);
  1126. fec_ver = STB0899_READ_S2REG(STB0899_S2FEC, FEC_VER_ID_REG);
  1127. if (! (chip_id > 0)) {
  1128. dprintk(state->verbose, FE_ERROR, 1, "couldn't find a STB 0899");
  1129. return -ENODEV;
  1130. }
  1131. dprintk(state->verbose, FE_ERROR, 1, "FEC Core ID=[%s], Version=[%d]", (char*) &fec_str, fec_ver);
  1132. return 0;
  1133. }
  1134. static void stb0899_set_delivery(struct stb0899_state *state)
  1135. {
  1136. u8 reg;
  1137. u8 stop_clk[2];
  1138. stop_clk[0] = stb0899_read_reg(state, STB0899_STOPCLK1);
  1139. stop_clk[1] = stb0899_read_reg(state, STB0899_STOPCLK2);
  1140. switch (state->delsys) {
  1141. case SYS_DVBS:
  1142. dprintk(state->verbose, FE_DEBUG, 1, "Delivery System -- DVB-S");
  1143. /* FECM/Viterbi ON */
  1144. reg = stb0899_read_reg(state, STB0899_FECM);
  1145. STB0899_SETFIELD_VAL(FECM_RSVD0, reg, 0);
  1146. STB0899_SETFIELD_VAL(FECM_VITERBI_ON, reg, 1);
  1147. stb0899_write_reg(state, STB0899_FECM, reg);
  1148. stb0899_write_reg(state, STB0899_RSULC, 0xb1);
  1149. stb0899_write_reg(state, STB0899_TSULC, 0x40);
  1150. stb0899_write_reg(state, STB0899_RSLLC, 0x42);
  1151. stb0899_write_reg(state, STB0899_TSLPL, 0x12);
  1152. reg = stb0899_read_reg(state, STB0899_TSTRES);
  1153. STB0899_SETFIELD_VAL(FRESLDPC, reg, 1);
  1154. stb0899_write_reg(state, STB0899_TSTRES, reg);
  1155. STB0899_SETFIELD_VAL(STOP_CHK8PSK, stop_clk[0], 1);
  1156. STB0899_SETFIELD_VAL(STOP_CKFEC108, stop_clk[0], 1);
  1157. STB0899_SETFIELD_VAL(STOP_CKFEC216, stop_clk[0], 1);
  1158. STB0899_SETFIELD_VAL(STOP_CKPKDLIN108, stop_clk[1], 1);
  1159. STB0899_SETFIELD_VAL(STOP_CKPKDLIN216, stop_clk[1], 1);
  1160. STB0899_SETFIELD_VAL(STOP_CKINTBUF216, stop_clk[0], 1);
  1161. STB0899_SETFIELD_VAL(STOP_CKCORE216, stop_clk[0], 0);
  1162. STB0899_SETFIELD_VAL(STOP_CKS2DMD108, stop_clk[1], 1);
  1163. break;
  1164. case SYS_DVBS2:
  1165. /* FECM/Viterbi OFF */
  1166. reg = stb0899_read_reg(state, STB0899_FECM);
  1167. STB0899_SETFIELD_VAL(FECM_RSVD0, reg, 0);
  1168. STB0899_SETFIELD_VAL(FECM_VITERBI_ON, reg, 0);
  1169. stb0899_write_reg(state, STB0899_FECM, reg);
  1170. stb0899_write_reg(state, STB0899_RSULC, 0xb1);
  1171. stb0899_write_reg(state, STB0899_TSULC, 0x42);
  1172. stb0899_write_reg(state, STB0899_RSLLC, 0x40);
  1173. stb0899_write_reg(state, STB0899_TSLPL, 0x02);
  1174. reg = stb0899_read_reg(state, STB0899_TSTRES);
  1175. STB0899_SETFIELD_VAL(FRESLDPC, reg, 0);
  1176. stb0899_write_reg(state, STB0899_TSTRES, reg);
  1177. STB0899_SETFIELD_VAL(STOP_CHK8PSK, stop_clk[0], 1);
  1178. STB0899_SETFIELD_VAL(STOP_CKFEC108, stop_clk[0], 0);
  1179. STB0899_SETFIELD_VAL(STOP_CKFEC216, stop_clk[0], 0);
  1180. STB0899_SETFIELD_VAL(STOP_CKPKDLIN108, stop_clk[1], 0);
  1181. STB0899_SETFIELD_VAL(STOP_CKPKDLIN216, stop_clk[1], 0);
  1182. STB0899_SETFIELD_VAL(STOP_CKINTBUF216, stop_clk[0], 0);
  1183. STB0899_SETFIELD_VAL(STOP_CKCORE216, stop_clk[0], 0);
  1184. STB0899_SETFIELD_VAL(STOP_CKS2DMD108, stop_clk[1], 0);
  1185. break;
  1186. case SYS_DSS:
  1187. /* FECM/Viterbi ON */
  1188. reg = stb0899_read_reg(state, STB0899_FECM);
  1189. STB0899_SETFIELD_VAL(FECM_RSVD0, reg, 1);
  1190. STB0899_SETFIELD_VAL(FECM_VITERBI_ON, reg, 1);
  1191. stb0899_write_reg(state, STB0899_FECM, reg);
  1192. stb0899_write_reg(state, STB0899_RSULC, 0xa1);
  1193. stb0899_write_reg(state, STB0899_TSULC, 0x61);
  1194. stb0899_write_reg(state, STB0899_RSLLC, 0x42);
  1195. reg = stb0899_read_reg(state, STB0899_TSTRES);
  1196. STB0899_SETFIELD_VAL(FRESLDPC, reg, 1);
  1197. stb0899_write_reg(state, STB0899_TSTRES, reg);
  1198. STB0899_SETFIELD_VAL(STOP_CHK8PSK, stop_clk[0], 1);
  1199. STB0899_SETFIELD_VAL(STOP_CKFEC108, stop_clk[0], 1);
  1200. STB0899_SETFIELD_VAL(STOP_CKFEC216, stop_clk[0], 1);
  1201. STB0899_SETFIELD_VAL(STOP_CKPKDLIN108, stop_clk[1], 1);
  1202. STB0899_SETFIELD_VAL(STOP_CKPKDLIN216, stop_clk[1], 1);
  1203. STB0899_SETFIELD_VAL(STOP_CKCORE216, stop_clk[0], 0);
  1204. STB0899_SETFIELD_VAL(STOP_CKS2DMD108, stop_clk[1], 1);
  1205. break;
  1206. default:
  1207. dprintk(state->verbose, FE_ERROR, 1, "Unsupported delivery system");
  1208. break;
  1209. }
  1210. STB0899_SETFIELD_VAL(STOP_CKADCI108, stop_clk[0], 0);
  1211. stb0899_write_regs(state, STB0899_STOPCLK1, stop_clk, 2);
  1212. }
  1213. /*
  1214. * stb0899_set_iterations
  1215. * set the LDPC iteration scale function
  1216. */
  1217. static void stb0899_set_iterations(struct stb0899_state *state)
  1218. {
  1219. struct stb0899_internal *internal = &state->internal;
  1220. struct stb0899_config *config = state->config;
  1221. s32 iter_scale;
  1222. u32 reg;
  1223. iter_scale = 17 * (internal->master_clk / 1000);
  1224. iter_scale += 410000;
  1225. iter_scale /= (internal->srate / 1000000);
  1226. iter_scale /= 1000;
  1227. if (iter_scale > config->ldpc_max_iter)
  1228. iter_scale = config->ldpc_max_iter;
  1229. reg = STB0899_READ_S2REG(STB0899_S2DEMOD, MAX_ITER);
  1230. STB0899_SETFIELD_VAL(MAX_ITERATIONS, reg, iter_scale);
  1231. stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_MAX_ITER, STB0899_OFF0_MAX_ITER, reg);
  1232. }
  1233. static enum dvbfe_search stb0899_search(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
  1234. {
  1235. struct stb0899_state *state = fe->demodulator_priv;
  1236. struct stb0899_params *i_params = &state->params;
  1237. struct stb0899_internal *internal = &state->internal;
  1238. struct stb0899_config *config = state->config;
  1239. struct dtv_frontend_properties *props = &fe->dtv_property_cache;
  1240. u32 SearchRange, gain;
  1241. i_params->freq = p->frequency;
  1242. i_params->srate = p->u.qpsk.symbol_rate;
  1243. state->delsys = props->delivery_system;
  1244. dprintk(state->verbose, FE_DEBUG, 1, "delivery system=%d", state->delsys);
  1245. SearchRange = 10000000;
  1246. dprintk(state->verbose, FE_DEBUG, 1, "Frequency=%d, Srate=%d", i_params->freq, i_params->srate);
  1247. /* checking Search Range is meaningless for a fixed 3 Mhz */
  1248. if (INRANGE(i_params->srate, 1000000, 45000000)) {
  1249. dprintk(state->verbose, FE_DEBUG, 1, "Parameters IN RANGE");
  1250. stb0899_set_delivery(state);
  1251. if (state->config->tuner_set_rfsiggain) {
  1252. if (internal->srate > 15000000)
  1253. gain = 8; /* 15Mb < srate < 45Mb, gain = 8dB */
  1254. else if (internal->srate > 5000000)
  1255. gain = 12; /* 5Mb < srate < 15Mb, gain = 12dB */
  1256. else
  1257. gain = 14; /* 1Mb < srate < 5Mb, gain = 14db */
  1258. state->config->tuner_set_rfsiggain(fe, gain);
  1259. }
  1260. if (i_params->srate <= 5000000)
  1261. stb0899_set_mclk(state, config->lo_clk);
  1262. else
  1263. stb0899_set_mclk(state, config->hi_clk);
  1264. switch (state->delsys) {
  1265. case SYS_DVBS:
  1266. case SYS_DSS:
  1267. dprintk(state->verbose, FE_DEBUG, 1, "DVB-S delivery system");
  1268. internal->freq = i_params->freq;
  1269. internal->srate = i_params->srate;
  1270. /*
  1271. * search = user search range +
  1272. * 500Khz +
  1273. * 2 * Tuner_step_size +
  1274. * 10% of the symbol rate
  1275. */
  1276. internal->srch_range = SearchRange + 1500000 + (i_params->srate / 5);
  1277. internal->derot_percent = 30;
  1278. /* What to do for tuners having no bandwidth setup ? */
  1279. /* enable tuner I/O */
  1280. stb0899_i2c_gate_ctrl(&state->frontend, 1);
  1281. if (state->config->tuner_set_bandwidth)
  1282. state->config->tuner_set_bandwidth(fe, (13 * (stb0899_carr_width(state) + SearchRange)) / 10);
  1283. if (state->config->tuner_get_bandwidth)
  1284. state->config->tuner_get_bandwidth(fe, &internal->tuner_bw);
  1285. /* disable tuner I/O */
  1286. stb0899_i2c_gate_ctrl(&state->frontend, 0);
  1287. /* Set DVB-S1 AGC */
  1288. stb0899_write_reg(state, STB0899_AGCRFCFG, 0x11);
  1289. /* Run the search algorithm */
  1290. dprintk(state->verbose, FE_DEBUG, 1, "running DVB-S search algo ..");
  1291. if (stb0899_dvbs_algo(state) == RANGEOK) {
  1292. internal->lock = 1;
  1293. dprintk(state->verbose, FE_DEBUG, 1,
  1294. "-------------------------------------> DVB-S LOCK !");
  1295. // stb0899_write_reg(state, STB0899_ERRCTRL1, 0x3d); /* Viterbi Errors */
  1296. // internal->v_status = stb0899_read_reg(state, STB0899_VSTATUS);
  1297. // internal->err_ctrl = stb0899_read_reg(state, STB0899_ERRCTRL1);
  1298. // dprintk(state->verbose, FE_DEBUG, 1, "VSTATUS=0x%02x", internal->v_status);
  1299. // dprintk(state->verbose, FE_DEBUG, 1, "ERR_CTRL=0x%02x", internal->err_ctrl);
  1300. return DVBFE_ALGO_SEARCH_SUCCESS;
  1301. } else {
  1302. internal->lock = 0;
  1303. return DVBFE_ALGO_SEARCH_FAILED;
  1304. }
  1305. break;
  1306. case SYS_DVBS2:
  1307. internal->freq = i_params->freq;
  1308. internal->srate = i_params->srate;
  1309. internal->srch_range = SearchRange;
  1310. /* enable tuner I/O */
  1311. stb0899_i2c_gate_ctrl(&state->frontend, 1);
  1312. if (state->config->tuner_set_bandwidth)
  1313. state->config->tuner_set_bandwidth(fe, (stb0899_carr_width(state) + SearchRange));
  1314. if (state->config->tuner_get_bandwidth)
  1315. state->config->tuner_get_bandwidth(fe, &internal->tuner_bw);
  1316. /* disable tuner I/O */
  1317. stb0899_i2c_gate_ctrl(&state->frontend, 0);
  1318. // pParams->SpectralInv = pSearch->IQ_Inversion;
  1319. /* Set DVB-S2 AGC */
  1320. stb0899_write_reg(state, STB0899_AGCRFCFG, 0x1c);
  1321. /* Set IterScale =f(MCLK,SYMB) */
  1322. stb0899_set_iterations(state);
  1323. /* Run the search algorithm */
  1324. dprintk(state->verbose, FE_DEBUG, 1, "running DVB-S2 search algo ..");
  1325. if (stb0899_dvbs2_algo(state) == DVBS2_FEC_LOCK) {
  1326. internal->lock = 1;
  1327. dprintk(state->verbose, FE_DEBUG, 1,
  1328. "-------------------------------------> DVB-S2 LOCK !");
  1329. // stb0899_write_reg(state, STB0899_ERRCTRL1, 0xb6); /* Packet Errors */
  1330. // internal->v_status = stb0899_read_reg(state, STB0899_VSTATUS);
  1331. // internal->err_ctrl = stb0899_read_reg(state, STB0899_ERRCTRL1);
  1332. return DVBFE_ALGO_SEARCH_SUCCESS;
  1333. } else {
  1334. internal->lock = 0;
  1335. return DVBFE_ALGO_SEARCH_FAILED;
  1336. }
  1337. break;
  1338. default:
  1339. dprintk(state->verbose, FE_ERROR, 1, "Unsupported delivery system");
  1340. return DVBFE_ALGO_SEARCH_INVALID;
  1341. }
  1342. }
  1343. return DVBFE_ALGO_SEARCH_ERROR;
  1344. }
  1345. /*
  1346. * stb0899_track
  1347. * periodically check the signal level against a specified
  1348. * threshold level and perform derotator centering.
  1349. * called once we have a lock from a successful search
  1350. * event.
  1351. *
  1352. * Will be called periodically called to maintain the
  1353. * lock.
  1354. *
  1355. * Will be used to get parameters as well as info from
  1356. * the decoded baseband header
  1357. *
  1358. * Once a new lock has established, the internal state
  1359. * frequency (internal->freq) is updated
  1360. */
  1361. static int stb0899_track(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
  1362. {
  1363. return 0;
  1364. }
  1365. static int stb0899_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
  1366. {
  1367. struct stb0899_state *state = fe->demodulator_priv;
  1368. struct stb0899_internal *internal = &state->internal;
  1369. dprintk(state->verbose, FE_DEBUG, 1, "Get params");
  1370. p->u.qpsk.symbol_rate = internal->srate;
  1371. return 0;
  1372. }
  1373. static enum dvbfe_algo stb0899_frontend_algo(struct dvb_frontend *fe)
  1374. {
  1375. return DVBFE_ALGO_CUSTOM;
  1376. }
  1377. static struct dvb_frontend_ops stb0899_ops = {
  1378. .info = {
  1379. .name = "STB0899 Multistandard",
  1380. .type = FE_QPSK,
  1381. .frequency_min = 950000,
  1382. .frequency_max = 2150000,
  1383. .frequency_stepsize = 0,
  1384. .frequency_tolerance = 0,
  1385. .symbol_rate_min = 5000000,
  1386. .symbol_rate_max = 45000000,
  1387. .caps = FE_CAN_INVERSION_AUTO |
  1388. FE_CAN_FEC_AUTO |
  1389. FE_CAN_2G_MODULATION |
  1390. FE_CAN_QPSK
  1391. },
  1392. .release = stb0899_release,
  1393. .init = stb0899_init,
  1394. .sleep = stb0899_sleep,
  1395. // .wakeup = stb0899_wakeup,
  1396. .i2c_gate_ctrl = stb0899_i2c_gate_ctrl,
  1397. .get_frontend_algo = stb0899_frontend_algo,
  1398. .search = stb0899_search,
  1399. .track = stb0899_track,
  1400. .get_frontend = stb0899_get_frontend,
  1401. .read_status = stb0899_read_status,
  1402. .read_snr = stb0899_read_snr,
  1403. .read_signal_strength = stb0899_read_signal_strength,
  1404. .read_ber = stb0899_read_ber,
  1405. .set_voltage = stb0899_set_voltage,
  1406. .set_tone = stb0899_set_tone,
  1407. .diseqc_send_master_cmd = stb0899_send_diseqc_msg,
  1408. .diseqc_recv_slave_reply = stb0899_recv_slave_reply,
  1409. .diseqc_send_burst = stb0899_send_diseqc_burst,
  1410. };
  1411. struct dvb_frontend *stb0899_attach(struct stb0899_config *config, struct i2c_adapter *i2c)
  1412. {
  1413. struct stb0899_state *state = NULL;
  1414. enum stb0899_inversion inversion;
  1415. state = kzalloc(sizeof (struct stb0899_state), GFP_KERNEL);
  1416. if (state == NULL)
  1417. goto error;
  1418. inversion = config->inversion;
  1419. state->verbose = &verbose;
  1420. state->config = config;
  1421. state->i2c = i2c;
  1422. state->frontend.ops = stb0899_ops;
  1423. state->frontend.demodulator_priv = state;
  1424. state->internal.inversion = inversion;
  1425. stb0899_wakeup(&state->frontend);
  1426. if (stb0899_get_dev_id(state) == -ENODEV) {
  1427. printk("%s: Exiting .. !\n", __func__);
  1428. goto error;
  1429. }
  1430. printk("%s: Attaching STB0899 \n", __func__);
  1431. return &state->frontend;
  1432. error:
  1433. kfree(state);
  1434. return NULL;
  1435. }
  1436. EXPORT_SYMBOL(stb0899_attach);
  1437. MODULE_PARM_DESC(verbose, "Set Verbosity level");
  1438. MODULE_AUTHOR("Manu Abraham");
  1439. MODULE_DESCRIPTION("STB0899 Multi-Std frontend");
  1440. MODULE_LICENSE("GPL");