stb0899_drv.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686
  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. return 0;
  627. }
  628. static int stb0899_wait_diseqc_rxidle(struct stb0899_state *state, int timeout)
  629. {
  630. u8 reg = 0;
  631. unsigned long start = jiffies;
  632. while (!STB0899_GETFIELD(RXEND, reg)) {
  633. reg = stb0899_read_reg(state, STB0899_DISRX_ST0);
  634. if (jiffies - start > timeout) {
  635. dprintk(state->verbose, FE_ERROR, 1, "timed out!!");
  636. return -ETIMEDOUT;
  637. }
  638. msleep(10);
  639. }
  640. return 0;
  641. }
  642. static int stb0899_recv_slave_reply(struct dvb_frontend *fe, struct dvb_diseqc_slave_reply *reply)
  643. {
  644. struct stb0899_state *state = fe->demodulator_priv;
  645. u8 reg, length = 0, i;
  646. int result;
  647. if (stb0899_wait_diseqc_rxidle(state, 100) < 0)
  648. return -ETIMEDOUT;
  649. reg = stb0899_read_reg(state, STB0899_DISRX_ST0);
  650. if (STB0899_GETFIELD(RXEND, reg)) {
  651. reg = stb0899_read_reg(state, STB0899_DISRX_ST1);
  652. length = STB0899_GETFIELD(FIFOBYTENBR, reg);
  653. if (length > sizeof (reply->msg)) {
  654. result = -EOVERFLOW;
  655. goto exit;
  656. }
  657. reply->msg_len = length;
  658. /* extract data */
  659. for (i = 0; i < length; i++)
  660. reply->msg[i] = stb0899_read_reg(state, STB0899_DISFIFO);
  661. }
  662. return 0;
  663. exit:
  664. return result;
  665. }
  666. static int stb0899_wait_diseqc_txidle(struct stb0899_state *state, int timeout)
  667. {
  668. u8 reg = 0;
  669. unsigned long start = jiffies;
  670. while (!STB0899_GETFIELD(TXIDLE, reg)) {
  671. reg = stb0899_read_reg(state, STB0899_DISSTATUS);
  672. if (jiffies - start > timeout) {
  673. dprintk(state->verbose, FE_ERROR, 1, "timed out!!");
  674. return -ETIMEDOUT;
  675. }
  676. msleep(10);
  677. }
  678. return 0;
  679. }
  680. static int stb0899_send_diseqc_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t burst)
  681. {
  682. struct stb0899_state *state = fe->demodulator_priv;
  683. u8 reg, old_state;
  684. /* wait for diseqc idle */
  685. if (stb0899_wait_diseqc_txidle(state, 100) < 0)
  686. return -ETIMEDOUT;
  687. reg = stb0899_read_reg(state, STB0899_DISCNTRL1);
  688. old_state = reg;
  689. /* set to burst mode */
  690. STB0899_SETFIELD_VAL(DISEQCMODE, reg, 0x03);
  691. STB0899_SETFIELD_VAL(DISPRECHARGE, reg, 0x01);
  692. stb0899_write_reg(state, STB0899_DISCNTRL1, reg);
  693. switch (burst) {
  694. case SEC_MINI_A:
  695. /* unmodulated */
  696. stb0899_write_reg(state, STB0899_DISFIFO, 0x00);
  697. break;
  698. case SEC_MINI_B:
  699. /* modulated */
  700. stb0899_write_reg(state, STB0899_DISFIFO, 0xff);
  701. break;
  702. }
  703. reg = stb0899_read_reg(state, STB0899_DISCNTRL1);
  704. STB0899_SETFIELD_VAL(DISPRECHARGE, reg, 0x00);
  705. stb0899_write_reg(state, STB0899_DISCNTRL1, reg);
  706. /* wait for diseqc idle */
  707. if (stb0899_wait_diseqc_txidle(state, 100) < 0)
  708. return -ETIMEDOUT;
  709. /* restore state */
  710. stb0899_write_reg(state, STB0899_DISCNTRL1, old_state);
  711. return 0;
  712. }
  713. static int stb0899_diseqc_init(struct stb0899_state *state)
  714. {
  715. struct dvb_diseqc_master_cmd tx_data;
  716. /*
  717. struct dvb_diseqc_slave_reply rx_data;
  718. */
  719. u8 f22_tx, f22_rx, reg;
  720. u32 mclk, tx_freq = 22000;/* count = 0, i; */
  721. tx_data.msg[0] = 0xe2;
  722. tx_data.msg_len = 3;
  723. reg = stb0899_read_reg(state, STB0899_DISCNTRL2);
  724. STB0899_SETFIELD_VAL(ONECHIP_TRX, reg, 0);
  725. stb0899_write_reg(state, STB0899_DISCNTRL2, reg);
  726. /* disable Tx spy */
  727. reg = stb0899_read_reg(state, STB0899_DISCNTRL1);
  728. STB0899_SETFIELD_VAL(DISEQCRESET, reg, 1);
  729. stb0899_write_reg(state, STB0899_DISCNTRL1, reg);
  730. reg = stb0899_read_reg(state, STB0899_DISCNTRL1);
  731. STB0899_SETFIELD_VAL(DISEQCRESET, reg, 0);
  732. stb0899_write_reg(state, STB0899_DISCNTRL1, reg);
  733. mclk = stb0899_get_mclk(state);
  734. f22_tx = mclk / (tx_freq * 32);
  735. stb0899_write_reg(state, STB0899_DISF22, f22_tx); /* DiSEqC Tx freq */
  736. state->rx_freq = 20000;
  737. f22_rx = mclk / (state->rx_freq * 32);
  738. return 0;
  739. }
  740. static int stb0899_sleep(struct dvb_frontend *fe)
  741. {
  742. struct stb0899_state *state = fe->demodulator_priv;
  743. /*
  744. u8 reg;
  745. */
  746. dprintk(state->verbose, FE_DEBUG, 1, "Going to Sleep .. (Really tired .. :-))");
  747. /* post process event */
  748. stb0899_postproc(state, STB0899_POSTPROC_GPIO_POWER, 0);
  749. return 0;
  750. }
  751. static int stb0899_wakeup(struct dvb_frontend *fe)
  752. {
  753. int rc;
  754. struct stb0899_state *state = fe->demodulator_priv;
  755. if ((rc = stb0899_write_reg(state, STB0899_SYNTCTRL, STB0899_SELOSCI)))
  756. return rc;
  757. /* Activate all clocks; DVB-S2 registers are inaccessible otherwise. */
  758. if ((rc = stb0899_write_reg(state, STB0899_STOPCLK1, 0x00)))
  759. return rc;
  760. if ((rc = stb0899_write_reg(state, STB0899_STOPCLK2, 0x00)))
  761. return rc;
  762. /* post process event */
  763. stb0899_postproc(state, STB0899_POSTPROC_GPIO_POWER, 1);
  764. return 0;
  765. }
  766. static int stb0899_init(struct dvb_frontend *fe)
  767. {
  768. int i;
  769. struct stb0899_state *state = fe->demodulator_priv;
  770. struct stb0899_config *config = state->config;
  771. dprintk(state->verbose, FE_DEBUG, 1, "Initializing STB0899 ... ");
  772. /* init device */
  773. dprintk(state->verbose, FE_DEBUG, 1, "init device");
  774. for (i = 0; config->init_dev[i].address != 0xffff; i++)
  775. stb0899_write_reg(state, config->init_dev[i].address, config->init_dev[i].data);
  776. dprintk(state->verbose, FE_DEBUG, 1, "init S2 demod");
  777. /* init S2 demod */
  778. for (i = 0; config->init_s2_demod[i].offset != 0xffff; i++)
  779. stb0899_write_s2reg(state, STB0899_S2DEMOD,
  780. config->init_s2_demod[i].base_address,
  781. config->init_s2_demod[i].offset,
  782. config->init_s2_demod[i].data);
  783. dprintk(state->verbose, FE_DEBUG, 1, "init S1 demod");
  784. /* init S1 demod */
  785. for (i = 0; config->init_s1_demod[i].address != 0xffff; i++)
  786. stb0899_write_reg(state, config->init_s1_demod[i].address, config->init_s1_demod[i].data);
  787. dprintk(state->verbose, FE_DEBUG, 1, "init S2 FEC");
  788. /* init S2 fec */
  789. for (i = 0; config->init_s2_fec[i].offset != 0xffff; i++)
  790. stb0899_write_s2reg(state, STB0899_S2FEC,
  791. config->init_s2_fec[i].base_address,
  792. config->init_s2_fec[i].offset,
  793. config->init_s2_fec[i].data);
  794. dprintk(state->verbose, FE_DEBUG, 1, "init TST");
  795. /* init test */
  796. for (i = 0; config->init_tst[i].address != 0xffff; i++)
  797. stb0899_write_reg(state, config->init_tst[i].address, config->init_tst[i].data);
  798. stb0899_init_calc(state);
  799. stb0899_diseqc_init(state);
  800. return 0;
  801. }
  802. static int stb0899_table_lookup(const struct stb0899_tab *tab, int max, int val)
  803. {
  804. int res = 0;
  805. int min = 0, med;
  806. if (val < tab[min].read)
  807. res = tab[min].real;
  808. else if (val >= tab[max].read)
  809. res = tab[max].real;
  810. else {
  811. while ((max - min) > 1) {
  812. med = (max + min) / 2;
  813. if (val >= tab[min].read && val < tab[med].read)
  814. max = med;
  815. else
  816. min = med;
  817. }
  818. res = ((val - tab[min].read) *
  819. (tab[max].real - tab[min].real) /
  820. (tab[max].read - tab[min].read)) +
  821. tab[min].real;
  822. }
  823. return res;
  824. }
  825. static int stb0899_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
  826. {
  827. struct stb0899_state *state = fe->demodulator_priv;
  828. struct stb0899_internal *internal = &state->internal;
  829. int val;
  830. u32 reg;
  831. switch (state->delsys) {
  832. case SYS_DVBS:
  833. case SYS_DSS:
  834. if (internal->lock) {
  835. reg = stb0899_read_reg(state, STB0899_VSTATUS);
  836. if (STB0899_GETFIELD(VSTATUS_LOCKEDVIT, reg)) {
  837. reg = stb0899_read_reg(state, STB0899_AGCIQIN);
  838. val = (s32)(s8)STB0899_GETFIELD(AGCIQVALUE, reg);
  839. *strength = stb0899_table_lookup(stb0899_dvbsrf_tab, ARRAY_SIZE(stb0899_dvbsrf_tab) - 1, val);
  840. *strength += 750;
  841. dprintk(state->verbose, FE_DEBUG, 1, "AGCIQVALUE = 0x%02x, C = %d * 0.1 dBm",
  842. val & 0xff, *strength);
  843. }
  844. }
  845. break;
  846. case SYS_DVBS2:
  847. if (internal->lock) {
  848. reg = STB0899_READ_S2REG(STB0899_DEMOD, IF_AGC_GAIN);
  849. val = STB0899_GETFIELD(IF_AGC_GAIN, reg);
  850. *strength = stb0899_table_lookup(stb0899_dvbs2rf_tab, ARRAY_SIZE(stb0899_dvbs2rf_tab) - 1, val);
  851. *strength += 750;
  852. dprintk(state->verbose, FE_DEBUG, 1, "IF_AGC_GAIN = 0x%04x, C = %d * 0.1 dBm",
  853. val & 0x3fff, *strength);
  854. }
  855. break;
  856. default:
  857. dprintk(state->verbose, FE_DEBUG, 1, "Unsupported delivery system");
  858. return -EINVAL;
  859. }
  860. return 0;
  861. }
  862. static int stb0899_read_snr(struct dvb_frontend *fe, u16 *snr)
  863. {
  864. struct stb0899_state *state = fe->demodulator_priv;
  865. struct stb0899_internal *internal = &state->internal;
  866. unsigned int val, quant, quantn = -1, est, estn = -1;
  867. u8 buf[2];
  868. u32 reg;
  869. reg = stb0899_read_reg(state, STB0899_VSTATUS);
  870. switch (state->delsys) {
  871. case SYS_DVBS:
  872. case SYS_DSS:
  873. if (internal->lock) {
  874. if (STB0899_GETFIELD(VSTATUS_LOCKEDVIT, reg)) {
  875. stb0899_read_regs(state, STB0899_NIRM, buf, 2);
  876. val = MAKEWORD16(buf[0], buf[1]);
  877. *snr = stb0899_table_lookup(stb0899_cn_tab, ARRAY_SIZE(stb0899_cn_tab) - 1, val);
  878. dprintk(state->verbose, FE_DEBUG, 1, "NIR = 0x%02x%02x = %u, C/N = %d * 0.1 dBm\n",
  879. buf[0], buf[1], val, *snr);
  880. }
  881. }
  882. break;
  883. case SYS_DVBS2:
  884. if (internal->lock) {
  885. reg = STB0899_READ_S2REG(STB0899_S2DEMOD, UWP_CNTRL1);
  886. quant = STB0899_GETFIELD(UWP_ESN0_QUANT, reg);
  887. reg = STB0899_READ_S2REG(STB0899_S2DEMOD, UWP_STAT2);
  888. est = STB0899_GETFIELD(ESN0_EST, reg);
  889. if (est == 1)
  890. val = 301; /* C/N = 30.1 dB */
  891. else if (est == 2)
  892. val = 270; /* C/N = 27.0 dB */
  893. else {
  894. /* quantn = 100 * log(quant^2) */
  895. quantn = stb0899_table_lookup(stb0899_quant_tab, ARRAY_SIZE(stb0899_quant_tab) - 1, quant * 100);
  896. /* estn = 100 * log(est) */
  897. estn = stb0899_table_lookup(stb0899_est_tab, ARRAY_SIZE(stb0899_est_tab) - 1, est);
  898. /* snr(dBm/10) = -10*(log(est)-log(quant^2)) => snr(dBm/10) = (100*log(quant^2)-100*log(est))/10 */
  899. val = (quantn - estn) / 10;
  900. }
  901. *snr = val;
  902. dprintk(state->verbose, FE_DEBUG, 1, "Es/N0 quant = %d (%d) estimate = %u (%d), C/N = %d * 0.1 dBm",
  903. quant, quantn, est, estn, val);
  904. }
  905. break;
  906. default:
  907. dprintk(state->verbose, FE_DEBUG, 1, "Unsupported delivery system");
  908. return -EINVAL;
  909. }
  910. return 0;
  911. }
  912. static int stb0899_read_status(struct dvb_frontend *fe, enum fe_status *status)
  913. {
  914. struct stb0899_state *state = fe->demodulator_priv;
  915. struct stb0899_internal *internal = &state->internal;
  916. u8 reg;
  917. *status = 0;
  918. switch (state->delsys) {
  919. case SYS_DVBS:
  920. case SYS_DSS:
  921. dprintk(state->verbose, FE_DEBUG, 1, "Delivery system DVB-S/DSS");
  922. if (internal->lock) {
  923. reg = stb0899_read_reg(state, STB0899_VSTATUS);
  924. if (STB0899_GETFIELD(VSTATUS_LOCKEDVIT, reg)) {
  925. dprintk(state->verbose, FE_DEBUG, 1, "--------> FE_HAS_CARRIER | FE_HAS_LOCK");
  926. *status |= FE_HAS_CARRIER | FE_HAS_LOCK;
  927. reg = stb0899_read_reg(state, STB0899_PLPARM);
  928. if (STB0899_GETFIELD(VITCURPUN, reg)) {
  929. dprintk(state->verbose, FE_DEBUG, 1, "--------> FE_HAS_VITERBI | FE_HAS_SYNC");
  930. *status |= FE_HAS_VITERBI | FE_HAS_SYNC;
  931. /* post process event */
  932. stb0899_postproc(state, STB0899_POSTPROC_GPIO_LOCK, 1);
  933. }
  934. }
  935. }
  936. break;
  937. case SYS_DVBS2:
  938. dprintk(state->verbose, FE_DEBUG, 1, "Delivery system DVB-S2");
  939. if (internal->lock) {
  940. reg = STB0899_READ_S2REG(STB0899_S2DEMOD, DMD_STAT2);
  941. if (STB0899_GETFIELD(UWP_LOCK, reg) && STB0899_GETFIELD(CSM_LOCK, reg)) {
  942. *status |= FE_HAS_CARRIER;
  943. dprintk(state->verbose, FE_DEBUG, 1,
  944. "UWP & CSM Lock ! ---> DVB-S2 FE_HAS_CARRIER");
  945. reg = stb0899_read_reg(state, STB0899_CFGPDELSTATUS1);
  946. if (STB0899_GETFIELD(CFGPDELSTATUS_LOCK, reg)) {
  947. *status |= FE_HAS_LOCK;
  948. dprintk(state->verbose, FE_DEBUG, 1,
  949. "Packet Delineator Locked ! -----> DVB-S2 FE_HAS_LOCK");
  950. }
  951. if (STB0899_GETFIELD(CONTINUOUS_STREAM, reg)) {
  952. *status |= FE_HAS_VITERBI;
  953. dprintk(state->verbose, FE_DEBUG, 1,
  954. "Packet Delineator found VITERBI ! -----> DVB-S2 FE_HAS_VITERBI");
  955. }
  956. if (STB0899_GETFIELD(ACCEPTED_STREAM, reg)) {
  957. *status |= FE_HAS_SYNC;
  958. dprintk(state->verbose, FE_DEBUG, 1,
  959. "Packet Delineator found SYNC ! -----> DVB-S2 FE_HAS_SYNC");
  960. /* post process event */
  961. stb0899_postproc(state, STB0899_POSTPROC_GPIO_LOCK, 1);
  962. }
  963. }
  964. }
  965. break;
  966. default:
  967. dprintk(state->verbose, FE_DEBUG, 1, "Unsupported delivery system");
  968. return -EINVAL;
  969. }
  970. return 0;
  971. }
  972. /*
  973. * stb0899_get_error
  974. * viterbi error for DVB-S/DSS
  975. * packet error for DVB-S2
  976. * Bit Error Rate or Packet Error Rate * 10 ^ 7
  977. */
  978. static int stb0899_read_ber(struct dvb_frontend *fe, u32 *ber)
  979. {
  980. struct stb0899_state *state = fe->demodulator_priv;
  981. struct stb0899_internal *internal = &state->internal;
  982. u8 lsb, msb;
  983. u32 i;
  984. *ber = 0;
  985. switch (state->delsys) {
  986. case SYS_DVBS:
  987. case SYS_DSS:
  988. if (internal->lock) {
  989. /* average 5 BER values */
  990. for (i = 0; i < 5; i++) {
  991. msleep(100);
  992. lsb = stb0899_read_reg(state, STB0899_ECNT1L);
  993. msb = stb0899_read_reg(state, STB0899_ECNT1M);
  994. *ber += MAKEWORD16(msb, lsb);
  995. }
  996. *ber /= 5;
  997. /* Viterbi Check */
  998. if (STB0899_GETFIELD(VSTATUS_PRFVIT, internal->v_status)) {
  999. /* Error Rate */
  1000. *ber *= 9766;
  1001. /* ber = ber * 10 ^ 7 */
  1002. *ber /= (-1 + (1 << (2 * STB0899_GETFIELD(NOE, internal->err_ctrl))));
  1003. *ber /= 8;
  1004. }
  1005. }
  1006. break;
  1007. case SYS_DVBS2:
  1008. if (internal->lock) {
  1009. /* Average 5 PER values */
  1010. for (i = 0; i < 5; i++) {
  1011. msleep(100);
  1012. lsb = stb0899_read_reg(state, STB0899_ECNT1L);
  1013. msb = stb0899_read_reg(state, STB0899_ECNT1M);
  1014. *ber += MAKEWORD16(msb, lsb);
  1015. }
  1016. /* ber = ber * 10 ^ 7 */
  1017. *ber *= 10000000;
  1018. *ber /= (-1 + (1 << (4 + 2 * STB0899_GETFIELD(NOE, internal->err_ctrl))));
  1019. }
  1020. break;
  1021. default:
  1022. dprintk(state->verbose, FE_DEBUG, 1, "Unsupported delivery system");
  1023. return -EINVAL;
  1024. }
  1025. return 0;
  1026. }
  1027. static int stb0899_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
  1028. {
  1029. struct stb0899_state *state = fe->demodulator_priv;
  1030. switch (voltage) {
  1031. case SEC_VOLTAGE_13:
  1032. stb0899_write_reg(state, STB0899_GPIO00CFG, 0x82);
  1033. stb0899_write_reg(state, STB0899_GPIO01CFG, 0x02);
  1034. stb0899_write_reg(state, STB0899_GPIO02CFG, 0x00);
  1035. break;
  1036. case SEC_VOLTAGE_18:
  1037. stb0899_write_reg(state, STB0899_GPIO00CFG, 0x02);
  1038. stb0899_write_reg(state, STB0899_GPIO01CFG, 0x02);
  1039. stb0899_write_reg(state, STB0899_GPIO02CFG, 0x82);
  1040. break;
  1041. case SEC_VOLTAGE_OFF:
  1042. stb0899_write_reg(state, STB0899_GPIO00CFG, 0x82);
  1043. stb0899_write_reg(state, STB0899_GPIO01CFG, 0x82);
  1044. stb0899_write_reg(state, STB0899_GPIO02CFG, 0x82);
  1045. break;
  1046. default:
  1047. return -EINVAL;
  1048. }
  1049. return 0;
  1050. }
  1051. static int stb0899_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
  1052. {
  1053. struct stb0899_state *state = fe->demodulator_priv;
  1054. struct stb0899_internal *internal = &state->internal;
  1055. u8 div, reg;
  1056. /* wait for diseqc idle */
  1057. if (stb0899_wait_diseqc_txidle(state, 100) < 0)
  1058. return -ETIMEDOUT;
  1059. switch (tone) {
  1060. case SEC_TONE_ON:
  1061. div = (internal->master_clk / 100) / 5632;
  1062. div = (div + 5) / 10;
  1063. stb0899_write_reg(state, STB0899_DISEQCOCFG, 0x66);
  1064. reg = stb0899_read_reg(state, STB0899_ACRPRESC);
  1065. STB0899_SETFIELD_VAL(ACRPRESC, reg, 0x03);
  1066. stb0899_write_reg(state, STB0899_ACRPRESC, reg);
  1067. stb0899_write_reg(state, STB0899_ACRDIV1, div);
  1068. break;
  1069. case SEC_TONE_OFF:
  1070. stb0899_write_reg(state, STB0899_DISEQCOCFG, 0x20);
  1071. break;
  1072. default:
  1073. return -EINVAL;
  1074. }
  1075. return 0;
  1076. }
  1077. int stb0899_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
  1078. {
  1079. int i2c_stat;
  1080. struct stb0899_state *state = fe->demodulator_priv;
  1081. i2c_stat = stb0899_read_reg(state, STB0899_I2CRPT);
  1082. if (i2c_stat < 0)
  1083. goto err;
  1084. if (enable) {
  1085. dprintk(state->verbose, FE_DEBUG, 1, "Enabling I2C Repeater ...");
  1086. i2c_stat |= STB0899_I2CTON;
  1087. if (stb0899_write_reg(state, STB0899_I2CRPT, i2c_stat) < 0)
  1088. goto err;
  1089. } else {
  1090. dprintk(state->verbose, FE_DEBUG, 1, "Disabling I2C Repeater ...");
  1091. i2c_stat &= ~STB0899_I2CTON;
  1092. if (stb0899_write_reg(state, STB0899_I2CRPT, i2c_stat) < 0)
  1093. goto err;
  1094. }
  1095. return 0;
  1096. err:
  1097. dprintk(state->verbose, FE_ERROR, 1, "I2C Repeater control failed");
  1098. return -EREMOTEIO;
  1099. }
  1100. static inline void CONVERT32(u32 x, char *str)
  1101. {
  1102. *str++ = (x >> 24) & 0xff;
  1103. *str++ = (x >> 16) & 0xff;
  1104. *str++ = (x >> 8) & 0xff;
  1105. *str++ = (x >> 0) & 0xff;
  1106. *str = '\0';
  1107. }
  1108. int stb0899_get_dev_id(struct stb0899_state *state)
  1109. {
  1110. u8 chip_id, release;
  1111. u16 id;
  1112. u32 demod_ver = 0, fec_ver = 0;
  1113. char demod_str[5] = { 0 };
  1114. char fec_str[5] = { 0 };
  1115. id = stb0899_read_reg(state, STB0899_DEV_ID);
  1116. dprintk(state->verbose, FE_DEBUG, 1, "ID reg=[0x%02x]", id);
  1117. chip_id = STB0899_GETFIELD(CHIP_ID, id);
  1118. release = STB0899_GETFIELD(CHIP_REL, id);
  1119. dprintk(state->verbose, FE_ERROR, 1, "Device ID=[%d], Release=[%d]",
  1120. chip_id, release);
  1121. CONVERT32(STB0899_READ_S2REG(STB0899_S2DEMOD, DMD_CORE_ID), (char *)&demod_str);
  1122. demod_ver = STB0899_READ_S2REG(STB0899_S2DEMOD, DMD_VERSION_ID);
  1123. dprintk(state->verbose, FE_ERROR, 1, "Demodulator Core ID=[%s], Version=[%d]", (char *) &demod_str, demod_ver);
  1124. CONVERT32(STB0899_READ_S2REG(STB0899_S2FEC, FEC_CORE_ID_REG), (char *)&fec_str);
  1125. fec_ver = STB0899_READ_S2REG(STB0899_S2FEC, FEC_VER_ID_REG);
  1126. if (! (chip_id > 0)) {
  1127. dprintk(state->verbose, FE_ERROR, 1, "couldn't find a STB 0899");
  1128. return -ENODEV;
  1129. }
  1130. dprintk(state->verbose, FE_ERROR, 1, "FEC Core ID=[%s], Version=[%d]", (char*) &fec_str, fec_ver);
  1131. return 0;
  1132. }
  1133. static void stb0899_set_delivery(struct stb0899_state *state)
  1134. {
  1135. u8 reg;
  1136. u8 stop_clk[2];
  1137. stop_clk[0] = stb0899_read_reg(state, STB0899_STOPCLK1);
  1138. stop_clk[1] = stb0899_read_reg(state, STB0899_STOPCLK2);
  1139. switch (state->delsys) {
  1140. case SYS_DVBS:
  1141. dprintk(state->verbose, FE_DEBUG, 1, "Delivery System -- DVB-S");
  1142. /* FECM/Viterbi ON */
  1143. reg = stb0899_read_reg(state, STB0899_FECM);
  1144. STB0899_SETFIELD_VAL(FECM_RSVD0, reg, 0);
  1145. STB0899_SETFIELD_VAL(FECM_VITERBI_ON, reg, 1);
  1146. stb0899_write_reg(state, STB0899_FECM, reg);
  1147. stb0899_write_reg(state, STB0899_RSULC, 0xb1);
  1148. stb0899_write_reg(state, STB0899_TSULC, 0x40);
  1149. stb0899_write_reg(state, STB0899_RSLLC, 0x42);
  1150. stb0899_write_reg(state, STB0899_TSLPL, 0x12);
  1151. reg = stb0899_read_reg(state, STB0899_TSTRES);
  1152. STB0899_SETFIELD_VAL(FRESLDPC, reg, 1);
  1153. stb0899_write_reg(state, STB0899_TSTRES, reg);
  1154. STB0899_SETFIELD_VAL(STOP_CHK8PSK, stop_clk[0], 1);
  1155. STB0899_SETFIELD_VAL(STOP_CKFEC108, stop_clk[0], 1);
  1156. STB0899_SETFIELD_VAL(STOP_CKFEC216, stop_clk[0], 1);
  1157. STB0899_SETFIELD_VAL(STOP_CKPKDLIN108, stop_clk[1], 1);
  1158. STB0899_SETFIELD_VAL(STOP_CKPKDLIN216, stop_clk[1], 1);
  1159. STB0899_SETFIELD_VAL(STOP_CKINTBUF216, stop_clk[0], 1);
  1160. STB0899_SETFIELD_VAL(STOP_CKCORE216, stop_clk[0], 0);
  1161. STB0899_SETFIELD_VAL(STOP_CKS2DMD108, stop_clk[1], 1);
  1162. break;
  1163. case SYS_DVBS2:
  1164. /* FECM/Viterbi OFF */
  1165. reg = stb0899_read_reg(state, STB0899_FECM);
  1166. STB0899_SETFIELD_VAL(FECM_RSVD0, reg, 0);
  1167. STB0899_SETFIELD_VAL(FECM_VITERBI_ON, reg, 0);
  1168. stb0899_write_reg(state, STB0899_FECM, reg);
  1169. stb0899_write_reg(state, STB0899_RSULC, 0xb1);
  1170. stb0899_write_reg(state, STB0899_TSULC, 0x42);
  1171. stb0899_write_reg(state, STB0899_RSLLC, 0x40);
  1172. stb0899_write_reg(state, STB0899_TSLPL, 0x02);
  1173. reg = stb0899_read_reg(state, STB0899_TSTRES);
  1174. STB0899_SETFIELD_VAL(FRESLDPC, reg, 0);
  1175. stb0899_write_reg(state, STB0899_TSTRES, reg);
  1176. STB0899_SETFIELD_VAL(STOP_CHK8PSK, stop_clk[0], 1);
  1177. STB0899_SETFIELD_VAL(STOP_CKFEC108, stop_clk[0], 0);
  1178. STB0899_SETFIELD_VAL(STOP_CKFEC216, stop_clk[0], 0);
  1179. STB0899_SETFIELD_VAL(STOP_CKPKDLIN108, stop_clk[1], 0);
  1180. STB0899_SETFIELD_VAL(STOP_CKPKDLIN216, stop_clk[1], 0);
  1181. STB0899_SETFIELD_VAL(STOP_CKINTBUF216, stop_clk[0], 0);
  1182. STB0899_SETFIELD_VAL(STOP_CKCORE216, stop_clk[0], 0);
  1183. STB0899_SETFIELD_VAL(STOP_CKS2DMD108, stop_clk[1], 0);
  1184. break;
  1185. case SYS_DSS:
  1186. /* FECM/Viterbi ON */
  1187. reg = stb0899_read_reg(state, STB0899_FECM);
  1188. STB0899_SETFIELD_VAL(FECM_RSVD0, reg, 1);
  1189. STB0899_SETFIELD_VAL(FECM_VITERBI_ON, reg, 1);
  1190. stb0899_write_reg(state, STB0899_FECM, reg);
  1191. stb0899_write_reg(state, STB0899_RSULC, 0xa1);
  1192. stb0899_write_reg(state, STB0899_TSULC, 0x61);
  1193. stb0899_write_reg(state, STB0899_RSLLC, 0x42);
  1194. reg = stb0899_read_reg(state, STB0899_TSTRES);
  1195. STB0899_SETFIELD_VAL(FRESLDPC, reg, 1);
  1196. stb0899_write_reg(state, STB0899_TSTRES, reg);
  1197. STB0899_SETFIELD_VAL(STOP_CHK8PSK, stop_clk[0], 1);
  1198. STB0899_SETFIELD_VAL(STOP_CKFEC108, stop_clk[0], 1);
  1199. STB0899_SETFIELD_VAL(STOP_CKFEC216, stop_clk[0], 1);
  1200. STB0899_SETFIELD_VAL(STOP_CKPKDLIN108, stop_clk[1], 1);
  1201. STB0899_SETFIELD_VAL(STOP_CKPKDLIN216, stop_clk[1], 1);
  1202. STB0899_SETFIELD_VAL(STOP_CKCORE216, stop_clk[0], 0);
  1203. STB0899_SETFIELD_VAL(STOP_CKS2DMD108, stop_clk[1], 1);
  1204. break;
  1205. default:
  1206. dprintk(state->verbose, FE_ERROR, 1, "Unsupported delivery system");
  1207. break;
  1208. }
  1209. STB0899_SETFIELD_VAL(STOP_CKADCI108, stop_clk[0], 0);
  1210. stb0899_write_regs(state, STB0899_STOPCLK1, stop_clk, 2);
  1211. }
  1212. /*
  1213. * stb0899_set_iterations
  1214. * set the LDPC iteration scale function
  1215. */
  1216. static void stb0899_set_iterations(struct stb0899_state *state)
  1217. {
  1218. struct stb0899_internal *internal = &state->internal;
  1219. struct stb0899_config *config = state->config;
  1220. s32 iter_scale;
  1221. u32 reg;
  1222. iter_scale = 17 * (internal->master_clk / 1000);
  1223. iter_scale += 410000;
  1224. iter_scale /= (internal->srate / 1000000);
  1225. iter_scale /= 1000;
  1226. if (iter_scale > config->ldpc_max_iter)
  1227. iter_scale = config->ldpc_max_iter;
  1228. reg = STB0899_READ_S2REG(STB0899_S2DEMOD, MAX_ITER);
  1229. STB0899_SETFIELD_VAL(MAX_ITERATIONS, reg, iter_scale);
  1230. stb0899_write_s2reg(state, STB0899_S2DEMOD, STB0899_BASE_MAX_ITER, STB0899_OFF0_MAX_ITER, reg);
  1231. }
  1232. static enum dvbfe_search stb0899_search(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
  1233. {
  1234. struct stb0899_state *state = fe->demodulator_priv;
  1235. struct stb0899_params *i_params = &state->params;
  1236. struct stb0899_internal *internal = &state->internal;
  1237. struct stb0899_config *config = state->config;
  1238. struct dtv_frontend_properties *props = &fe->dtv_property_cache;
  1239. u32 SearchRange, gain;
  1240. i_params->freq = p->frequency;
  1241. i_params->srate = p->u.qpsk.symbol_rate;
  1242. state->delsys = props->delivery_system;
  1243. dprintk(state->verbose, FE_DEBUG, 1, "delivery system=%d", state->delsys);
  1244. SearchRange = 10000000;
  1245. dprintk(state->verbose, FE_DEBUG, 1, "Frequency=%d, Srate=%d", i_params->freq, i_params->srate);
  1246. /* checking Search Range is meaningless for a fixed 3 Mhz */
  1247. if (INRANGE(i_params->srate, 1000000, 45000000)) {
  1248. dprintk(state->verbose, FE_DEBUG, 1, "Parameters IN RANGE");
  1249. stb0899_set_delivery(state);
  1250. if (state->config->tuner_set_rfsiggain) {
  1251. if (internal->srate > 15000000)
  1252. gain = 8; /* 15Mb < srate < 45Mb, gain = 8dB */
  1253. else if (internal->srate > 5000000)
  1254. gain = 12; /* 5Mb < srate < 15Mb, gain = 12dB */
  1255. else
  1256. gain = 14; /* 1Mb < srate < 5Mb, gain = 14db */
  1257. state->config->tuner_set_rfsiggain(fe, gain);
  1258. }
  1259. if (i_params->srate <= 5000000)
  1260. stb0899_set_mclk(state, config->lo_clk);
  1261. else
  1262. stb0899_set_mclk(state, config->hi_clk);
  1263. switch (state->delsys) {
  1264. case SYS_DVBS:
  1265. case SYS_DSS:
  1266. dprintk(state->verbose, FE_DEBUG, 1, "DVB-S delivery system");
  1267. internal->freq = i_params->freq;
  1268. internal->srate = i_params->srate;
  1269. /*
  1270. * search = user search range +
  1271. * 500Khz +
  1272. * 2 * Tuner_step_size +
  1273. * 10% of the symbol rate
  1274. */
  1275. internal->srch_range = SearchRange + 1500000 + (i_params->srate / 5);
  1276. internal->derot_percent = 30;
  1277. /* What to do for tuners having no bandwidth setup ? */
  1278. /* enable tuner I/O */
  1279. stb0899_i2c_gate_ctrl(&state->frontend, 1);
  1280. if (state->config->tuner_set_bandwidth)
  1281. state->config->tuner_set_bandwidth(fe, (13 * (stb0899_carr_width(state) + SearchRange)) / 10);
  1282. if (state->config->tuner_get_bandwidth)
  1283. state->config->tuner_get_bandwidth(fe, &internal->tuner_bw);
  1284. /* disable tuner I/O */
  1285. stb0899_i2c_gate_ctrl(&state->frontend, 0);
  1286. /* Set DVB-S1 AGC */
  1287. stb0899_write_reg(state, STB0899_AGCRFCFG, 0x11);
  1288. /* Run the search algorithm */
  1289. dprintk(state->verbose, FE_DEBUG, 1, "running DVB-S search algo ..");
  1290. if (stb0899_dvbs_algo(state) == RANGEOK) {
  1291. internal->lock = 1;
  1292. dprintk(state->verbose, FE_DEBUG, 1,
  1293. "-------------------------------------> DVB-S LOCK !");
  1294. // stb0899_write_reg(state, STB0899_ERRCTRL1, 0x3d); /* Viterbi Errors */
  1295. // internal->v_status = stb0899_read_reg(state, STB0899_VSTATUS);
  1296. // internal->err_ctrl = stb0899_read_reg(state, STB0899_ERRCTRL1);
  1297. // dprintk(state->verbose, FE_DEBUG, 1, "VSTATUS=0x%02x", internal->v_status);
  1298. // dprintk(state->verbose, FE_DEBUG, 1, "ERR_CTRL=0x%02x", internal->err_ctrl);
  1299. return DVBFE_ALGO_SEARCH_SUCCESS;
  1300. } else {
  1301. internal->lock = 0;
  1302. return DVBFE_ALGO_SEARCH_FAILED;
  1303. }
  1304. break;
  1305. case SYS_DVBS2:
  1306. internal->freq = i_params->freq;
  1307. internal->srate = i_params->srate;
  1308. internal->srch_range = SearchRange;
  1309. /* enable tuner I/O */
  1310. stb0899_i2c_gate_ctrl(&state->frontend, 1);
  1311. if (state->config->tuner_set_bandwidth)
  1312. state->config->tuner_set_bandwidth(fe, (stb0899_carr_width(state) + SearchRange));
  1313. if (state->config->tuner_get_bandwidth)
  1314. state->config->tuner_get_bandwidth(fe, &internal->tuner_bw);
  1315. /* disable tuner I/O */
  1316. stb0899_i2c_gate_ctrl(&state->frontend, 0);
  1317. // pParams->SpectralInv = pSearch->IQ_Inversion;
  1318. /* Set DVB-S2 AGC */
  1319. stb0899_write_reg(state, STB0899_AGCRFCFG, 0x1c);
  1320. /* Set IterScale =f(MCLK,SYMB) */
  1321. stb0899_set_iterations(state);
  1322. /* Run the search algorithm */
  1323. dprintk(state->verbose, FE_DEBUG, 1, "running DVB-S2 search algo ..");
  1324. if (stb0899_dvbs2_algo(state) == DVBS2_FEC_LOCK) {
  1325. internal->lock = 1;
  1326. dprintk(state->verbose, FE_DEBUG, 1,
  1327. "-------------------------------------> DVB-S2 LOCK !");
  1328. // stb0899_write_reg(state, STB0899_ERRCTRL1, 0xb6); /* Packet Errors */
  1329. // internal->v_status = stb0899_read_reg(state, STB0899_VSTATUS);
  1330. // internal->err_ctrl = stb0899_read_reg(state, STB0899_ERRCTRL1);
  1331. return DVBFE_ALGO_SEARCH_SUCCESS;
  1332. } else {
  1333. internal->lock = 0;
  1334. return DVBFE_ALGO_SEARCH_FAILED;
  1335. }
  1336. break;
  1337. default:
  1338. dprintk(state->verbose, FE_ERROR, 1, "Unsupported delivery system");
  1339. return DVBFE_ALGO_SEARCH_INVALID;
  1340. }
  1341. }
  1342. return DVBFE_ALGO_SEARCH_ERROR;
  1343. }
  1344. /*
  1345. * stb0899_track
  1346. * periodically check the signal level against a specified
  1347. * threshold level and perform derotator centering.
  1348. * called once we have a lock from a successful search
  1349. * event.
  1350. *
  1351. * Will be called periodically called to maintain the
  1352. * lock.
  1353. *
  1354. * Will be used to get parameters as well as info from
  1355. * the decoded baseband header
  1356. *
  1357. * Once a new lock has established, the internal state
  1358. * frequency (internal->freq) is updated
  1359. */
  1360. static int stb0899_track(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
  1361. {
  1362. return 0;
  1363. }
  1364. static int stb0899_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
  1365. {
  1366. struct stb0899_state *state = fe->demodulator_priv;
  1367. struct stb0899_internal *internal = &state->internal;
  1368. dprintk(state->verbose, FE_DEBUG, 1, "Get params");
  1369. p->u.qpsk.symbol_rate = internal->srate;
  1370. return 0;
  1371. }
  1372. static enum dvbfe_algo stb0899_frontend_algo(struct dvb_frontend *fe)
  1373. {
  1374. return DVBFE_ALGO_CUSTOM;
  1375. }
  1376. static struct dvb_frontend_ops stb0899_ops = {
  1377. .info = {
  1378. .name = "STB0899 Multistandard",
  1379. .type = FE_QPSK,
  1380. .frequency_min = 950000,
  1381. .frequency_max = 2150000,
  1382. .frequency_stepsize = 0,
  1383. .frequency_tolerance = 0,
  1384. .symbol_rate_min = 5000000,
  1385. .symbol_rate_max = 45000000,
  1386. .caps = FE_CAN_INVERSION_AUTO |
  1387. FE_CAN_FEC_AUTO |
  1388. FE_CAN_2G_MODULATION |
  1389. FE_CAN_QPSK
  1390. },
  1391. .release = stb0899_release,
  1392. .init = stb0899_init,
  1393. .sleep = stb0899_sleep,
  1394. // .wakeup = stb0899_wakeup,
  1395. .i2c_gate_ctrl = stb0899_i2c_gate_ctrl,
  1396. .get_frontend_algo = stb0899_frontend_algo,
  1397. .search = stb0899_search,
  1398. .track = stb0899_track,
  1399. .get_frontend = stb0899_get_frontend,
  1400. .read_status = stb0899_read_status,
  1401. .read_snr = stb0899_read_snr,
  1402. .read_signal_strength = stb0899_read_signal_strength,
  1403. .read_ber = stb0899_read_ber,
  1404. .set_voltage = stb0899_set_voltage,
  1405. .set_tone = stb0899_set_tone,
  1406. .diseqc_send_master_cmd = stb0899_send_diseqc_msg,
  1407. .diseqc_recv_slave_reply = stb0899_recv_slave_reply,
  1408. .diseqc_send_burst = stb0899_send_diseqc_burst,
  1409. };
  1410. struct dvb_frontend *stb0899_attach(struct stb0899_config *config, struct i2c_adapter *i2c)
  1411. {
  1412. struct stb0899_state *state = NULL;
  1413. enum stb0899_inversion inversion;
  1414. state = kzalloc(sizeof (struct stb0899_state), GFP_KERNEL);
  1415. if (state == NULL)
  1416. goto error;
  1417. inversion = config->inversion;
  1418. state->verbose = &verbose;
  1419. state->config = config;
  1420. state->i2c = i2c;
  1421. state->frontend.ops = stb0899_ops;
  1422. state->frontend.demodulator_priv = state;
  1423. state->internal.inversion = inversion;
  1424. stb0899_wakeup(&state->frontend);
  1425. if (stb0899_get_dev_id(state) == -ENODEV) {
  1426. printk("%s: Exiting .. !\n", __func__);
  1427. goto error;
  1428. }
  1429. printk("%s: Attaching STB0899 \n", __func__);
  1430. return &state->frontend;
  1431. error:
  1432. kfree(state);
  1433. return NULL;
  1434. }
  1435. EXPORT_SYMBOL(stb0899_attach);
  1436. MODULE_PARM_DESC(verbose, "Set Verbosity level");
  1437. MODULE_AUTHOR("Manu Abraham");
  1438. MODULE_DESCRIPTION("STB0899 Multi-Std frontend");
  1439. MODULE_LICENSE("GPL");