stb0899_drv.c 44 KB

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