stb0899_drv.c 45 KB

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